Skip to content

test: allocation-free hot-path verification (#217) - #308

Merged
Chris-Wolfgang merged 1 commit into
vNextfrom
thorough/217-alloc-free
Jul 23, 2026
Merged

test: allocation-free hot-path verification (#217)#308
Chris-Wolfgang merged 1 commit into
vNextfrom
thorough/217-alloc-free

Conversation

@Chris-Wolfgang

Copy link
Copy Markdown
Owner

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 (returns double?)
  • Report.EstimatedRemaining (returns TimeSpan?)
  • 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

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>
Copilot AI review requested due to automatic review settings July 22, 2026 17:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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