From e74957dd14d0b1d996ae7b67f000f2bb6296c6a7 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 2 Jul 2025 17:01:13 +0300 Subject: perf: implement tiered buffer pooling to reduce allocations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add scanner_pool.go with tiered buffer pools (1MB, 64KB, 4KB) - Modify readWithProcessorOptimized to use pooled scanner buffers - Update tailWithProcessorOptimized to pool 64KB read buffers - Increase BytesBuffer pool initial capacity from 128B to 4KB - Add buffer_pool_test.go to benchmark pooling effectiveness This reduces memory allocations by ~36% in turbo mode by reusing buffers instead of allocating new ones for each file operation. All integration tests pass. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- internal/io/pool/bytesbuffer.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'internal/io/pool/bytesbuffer.go') diff --git a/internal/io/pool/bytesbuffer.go b/internal/io/pool/bytesbuffer.go index 3d48f2c..21871f1 100644 --- a/internal/io/pool/bytesbuffer.go +++ b/internal/io/pool/bytesbuffer.go @@ -10,7 +10,9 @@ import ( var BytesBuffer = sync.Pool{ New: func() interface{} { b := bytes.Buffer{} - b.Grow(128) + // Increase initial capacity to 4KB to reduce reallocations + // Most log lines are between 100-500 bytes, but some can be larger + b.Grow(4096) return &b }, } -- cgit v1.2.3