test(format): measure realistic allocations in Format/Append benchmarks#224
Conversation
The Format*/Append* benchmarks discarded their result with "_ =". For inlinable functions such as FormatUint, escape analysis then kept the returned string on the stack, reporting a misleading 0 allocs/op that real callers, which retain the string, never observe. Switch the loops to b.Loop() (Go 1.24+). b.Loop keeps the call results alive so the value escapes, and the benchmark measures the true allocation cost, giving a fair fiber-vs-strconv comparison. It also resolves the modernize linter's "bloop" suggestion for these loops. Measured (FormatUint/medium): before, "_ =" discard: 0 B/op, 0 allocs/op (misleading) after, b.Loop(): 16 B/op, 1 allocs/op (the real cost) No production code changed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #224 +/- ##
=======================================
Coverage 84.02% 84.02%
=======================================
Files 14 14
Lines 1158 1158
=======================================
Hits 973 973
Misses 154 154
Partials 31 31
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
21fb997 to
2f1a488
Compare
|
Warning Review limit reached
More reviews will be available in 56 minutes and 44 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window. Please see our Fair Usage Limits Policy for further information. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
The
Format*/Append*benchmarks discarded their result with_ =. Forinlinable functions such as
FormatUint, escape analysis then kept the returnedstring on the stack, reporting a misleading
0 allocs/opthat real callers,which retain the returned string, never observe.
This switches the benchmark loops to
b.Loop()(Go 1.24+).b.Loop()keeps callresults alive, so the value escapes and the benchmark measures the true allocation
cost - giving a fair
fibervsstrconvcomparison. As a bonus it resolves themodernizelinter'sbloopsuggestion for these loops.Measured impact (methodology fix, not a perf change)
FormatUint/medium:_ =discard)b.Loop())Genuine
fiberwins stay visible and honest: the small-value cache (e.g.FormatInt/small_neg: 0 allocs vs strconv's 1) andFormatUint32(CPU). Theapparent advantage for small positive values was itself a measurement artifact
and correctly disappears under
b.Loop().Notes
format_test.go.gofumpt,go vetandgolangci-lintv2.6.1 are clean for the changed file.🤖 Generated with Claude Code