test: allocation-free hot-path verification (#217) - #308
Merged
Conversation
Adds tests/…Tests.Unit/Performance/AllocationFreeTests.cs. Some members are read or invoked once per record / progress tick and must not allocate — a change that "looks identical but allocates" silently regresses throughput and GC pressure for high-volume consumers. Each test measures managed allocation on the current thread across a tight loop (GC.GetAllocatedBytesForCurrentThread, available on every TFM net462+/netcoreapp3.1+) and asserts it rounds to zero per call. Documented allocation-free allowlist (asserted): Report.CurrentItemCount / ItemsPerSecond / PercentComplete (double?) / EstimatedRemaining (TimeSpan?), and ExtractorBase.IncrementCurrentItemCount / IncrementCurrentSkippedItemCount (Interlocked). The per-call threshold is a sub-byte epsilon to absorb one-time tiered-JIT recompilation amortised across the loop; a real per-call allocation (boxing, closure) is >=24 bytes and fails cleanly with the actual byte count. Verified: 6/6 green on net10.0 and net48. Closes #217 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jul 24, 2026
This was referenced Aug 5, 2026
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.
Summary
Adds
tests/…Tests.Unit/Performance/AllocationFreeTests.cs(issue #217). Members read/invoked once per record or per progress tick must not allocate — a change that "looks identical but allocates" silently regresses throughput and GC pressure for high-volume consumers, with nothing to catch it today.Each test measures managed allocation on the current thread across a tight loop via
GC.GetAllocatedBytesForCurrentThread()(available on every target framework — net462+ and netcoreapp3.1+) and asserts it rounds to zero per call.Documented allocation-free allowlist (asserted — anything not listed makes no promise):
Report.CurrentItemCount(field read)Report.ItemsPerSecond(value-type arithmetic)Report.PercentComplete(returnsdouble?)Report.EstimatedRemaining(returnsTimeSpan?)ExtractorBase.IncrementCurrentItemCount()/IncrementCurrentSkippedItemCount()(Interlocked, exercised via a harness subclass)Threshold: a sub-byte epsilon per call (not a hard 0) absorbs one-time tiered-JIT recompilation during the measured loop, amortised across 10k iterations. A real per-call allocation (a boxed value, a captured closure) is ≥24 bytes and fails cleanly with the actual byte count and call site.
Verification
6/6 green in Release on net10.0 and net48 (confirms the surface is alloc-free on both the modern and .NET Framework runtimes).
Additive test-only change.
Closes #217