Conversation
samber
commented
Mar 24, 2026
- perf(pool): eliminate slice allocation in Handle hot path
- perf(inline): prealloc slices in WithAttrs and WithGroup
- test: add benchmarks, adversarial tests, and improved fuzz coverage (test: add benchmarks, adversarial tests, and improved fuzz coverage #50)
Replace slice copy with index arithmetic for round-robin handler selection. This removes 1 allocation per log record (48-160B depending on handler count), yielding 13-37% latency improvement.
Use make() with exact capacity instead of empty slice literals followed by double appends. Eliminates unnecessary reallocation during slice growth in InlineHandler and HandleInlineHandler.
There was a problem hiding this comment.
Pull request overview
Performance-focused update to slogmulti handlers (especially Pool and inline handlers) while expanding stress/fuzz/benchmark coverage and wiring fuzzing into CI.
Changes:
- Optimize
PoolHandler.Handleto avoid per-call slice allocation by using index arithmetic. - Preallocate slices in
WithAttrs/WithGroupfor inline handler implementations to reduce allocations. - Strengthen testing/measurement via stress test adjustment, fuzz fixes, benchmark tweak, and CI fuzz job.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
pool.go |
Removes slice rotation allocation in PoolHandler.Handle by iterating with modular indexing. |
handler_inline.go |
Preallocates attribute/group slices in WithAttrs/WithGroup. |
handler_inline_handle.go |
Preallocates attribute/group slices in WithAttrs/WithGroup. |
stress_test.go |
Avoids concurrent test assertions by counting errors with atomic.Int64. |
fuzz_test.go |
Normalizes mode%4 to handle negative values in FuzzRecoveryHandle. |
benchmark_test.go |
Reuses a single slog.Record in BenchmarkFanoutHandle to reduce benchmark overhead. |
Makefile |
Adds a fuzz target (configurable via FUZZTIME). |
.github/workflows/test.yml |
Adds a CI fuzz step (Go 1.22 only). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix Codecov condition: matrix.go == '1.22' (was '1.21' which no longer exists in the matrix) - Benchmark consistency: reuse pre-created record in all non-parallel benchmarks to avoid measuring benchRecord() allocation overhead - Deduplicate fuzz mode normalization: compute ((mode%4)+4)%4 once into normalizedMode variable
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #51 +/- ##
===========================================
+ Coverage 29.20% 54.06% +24.85%
===========================================
Files 16 16
Lines 493 492 -1
===========================================
+ Hits 144 266 +122
+ Misses 340 216 -124
- Partials 9 10 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|