bench: foreach vs ReadGroups callback decode benchmark (#156)#161
Merged
Conversation
Adds GroupForeachVsCallbackBenchmarks comparing the v1.5.0 foreach-style
group enumerator against the original ReadGroups callback API on
MarketDataData (two simple top-level groups), parameterized over
GroupSize ∈ {10, 50, 100}.
Results on AMD EPYC 7763 / .NET 9 (GroupSize=100):
Callback 999 ns 152 B 1.00x
Foreach 184 ns 0 B 0.18x
Foreach + break 3 ns 0 B 0.003x
Foreach is ~5x faster on full iteration and eliminates the 152 B
per-call closure allocation. Early break is essentially free because
each group property does an O(1) skip rather than running every entry.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Follow-up to #156 / PR #158 (v1.5.0): we shipped the foreach-style group enumerator with the claim that it's faster and zero-alloc compared to the existing
ReadGroupscallback API. This PR backs that claim with numbers.What
Adds
GroupForeachVsCallbackBenchmarkscomparing three decode strategies onMarketDataData(two simple top-level groups, qualifies for foreach), parameterized overGroupSize ∈ {10, 50, 100}:ReadGroupswith capturing lambdas (mirrors the most common user pattern: closure allocation per call)Workload (identical across variants): sum
Price.Value + Quantity.Valueover every entry, returned to defeat dead-code elimination.Results
AMD EPYC 7763, .NET 9.0.14, BenchmarkDotNet v0.15.4:
Takeaways
sum).Notes
RepeatingGroupBenchmarks.DecodeWithGroupsis left untouched — it does encode+decode in the hot path and isn't directly comparable. New file is focused (decode-only, pre-encoded buffer).<sbe:message name=\"MarketData\">which has only simple top-level groups, so it qualifies for the foreach emit path.benchmarks/updated with the new benchmark description and reference numbers.