mirror of
https://github.com/j3ssie/osmedeus.git
synced 2026-08-23 08:02:26 +02:00
- 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)
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
// Package utils provides shared utility functions
|
|
package utils
|
|
|
|
import "sync"
|
|
|
|
// LargeBufferSize is the default size for large buffers (10MB)
|
|
const LargeBufferSize = 10 * 1024 * 1024
|
|
|
|
// largeBufferPool provides reusable 10MB buffers to reduce allocation overhead
|
|
var largeBufferPool = sync.Pool{
|
|
New: func() interface{} {
|
|
buf := make([]byte, LargeBufferSize)
|
|
return &buf
|
|
},
|
|
}
|
|
|
|
// GetLargeBuffer retrieves a 10MB buffer from the pool
|
|
func GetLargeBuffer() *[]byte {
|
|
return largeBufferPool.Get().(*[]byte)
|
|
}
|
|
|
|
// PutLargeBuffer returns a buffer to the pool
|
|
// The buffer slice will be reset to full capacity
|
|
func PutLargeBuffer(buf *[]byte) {
|
|
if buf == nil {
|
|
return
|
|
}
|
|
// Reset to full capacity
|
|
*buf = (*buf)[:cap(*buf)]
|
|
largeBufferPool.Put(buf)
|
|
}
|
|
|
|
// GetScannerBuffer retrieves a buffer suitable for bufio.Scanner
|
|
// Returns both initial buffer and max size for Scanner.Buffer()
|
|
func GetScannerBuffer() ([]byte, int) {
|
|
buf := GetLargeBuffer()
|
|
return (*buf)[:64*1024], LargeBufferSize // initial 64KB, max 10MB
|
|
}
|