Skip to content

perf/optimizations#51

Merged
samber merged 4 commits intomainfrom
perf/optimizations
Mar 24, 2026
Merged

perf/optimizations#51
samber merged 4 commits intomainfrom
perf/optimizations

Conversation

@samber
Copy link
Copy Markdown
Owner

@samber samber commented Mar 24, 2026

samber added 3 commits March 24, 2026 19:15
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.
Copilot AI review requested due to automatic review settings March 24, 2026 18:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Handle to avoid per-call slice allocation by using index arithmetic.
  • Preallocate slices in WithAttrs/WithGroup for 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.

Comment thread .github/workflows/test.yml
Comment thread benchmark_test.go
Comment thread fuzz_test.go Outdated
Comment thread fuzz_test.go Outdated
- 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
@samber samber merged commit 8caa06f into main Mar 24, 2026
14 checks passed
@samber samber deleted the perf/optimizations branch March 24, 2026 18:52
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.06%. Comparing base (047aba8) to head (2062ad2).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
handler_inline.go 0.00% 2 Missing ⚠️
handler_inline_handle.go 0.00% 2 Missing ⚠️
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     
Flag Coverage Δ
unittests 54.06% <50.00%> (+24.85%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants