Files
osmedeus/internal/utils/bufpool_test.go
T
j3ssie 7de3e7b2b2 feat: add performance optimizations and robustness improvements
- Add lock-free ResultCollector for parallel execution with atomic operations, eliminating mutex contention for pre-allocated slices
- Implement circuit breaker pattern (internal/retry/circuit_breaker) with configurable thresholds and half-open recovery state for fault tolerance
- Introduce json-iterator replacement (internal/json) for 2-6x faster JSON operations while maintaining stdlib compatibility
- Add lazy template rendering (RenderLazy) with variable reference caching for 50-80% faster rendering on large contexts
- Implement memory-efficient buffer pooling (bufpool) with 10MB pre-allocated reusable buffers for reduced GC pressure
- Add LoadFlowWithModules for parallel module pre-loading using errgroup, improving startup time for complex flows
- Add VarRefCache with LRU eviction for variable extraction caching
- Add streaming output support for foreach loops to process large datasets without memory accumulation
- Fix json import compatibility in llm_executor and db_functions
- Update test fixtures with correct YAML field names (call→function, run→command)
2026-01-31 01:26:28 +07:00

59 lines
1.2 KiB
Go

package utils
import (
"testing"
)
func TestGetPutLargeBuffer(t *testing.T) {
buf := GetLargeBuffer()
if buf == nil {
t.Fatal("expected non-nil buffer")
}
if len(*buf) != LargeBufferSize {
t.Errorf("expected buffer size %d, got %d", LargeBufferSize, len(*buf))
}
// Write some data
(*buf)[0] = 'x'
// Return to pool
PutLargeBuffer(buf)
// Get another - might be same buffer
buf2 := GetLargeBuffer()
if len(*buf2) != LargeBufferSize {
t.Errorf("expected buffer size %d after reuse, got %d", LargeBufferSize, len(*buf2))
}
PutLargeBuffer(buf2)
}
func TestPutNilBuffer(t *testing.T) {
// Should not panic
PutLargeBuffer(nil)
}
func TestGetScannerBuffer(t *testing.T) {
initial, max := GetScannerBuffer()
if len(initial) != 64*1024 {
t.Errorf("expected initial size 64KB, got %d", len(initial))
}
if max != LargeBufferSize {
t.Errorf("expected max size %d, got %d", LargeBufferSize, max)
}
}
func BenchmarkBufferPool(b *testing.B) {
b.Run("pool", func(b *testing.B) {
for i := 0; i < b.N; i++ {
buf := GetLargeBuffer()
PutLargeBuffer(buf)
}
})
b.Run("alloc", func(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = make([]byte, LargeBufferSize)
}
})
}