Skip to content

fix: warm native timer locks before batch allocation measurement - #587

Merged
thomhurst merged 1 commit into
mainfrom
issue-585-batch-allocation
Nov 13, 2026
Merged

thomhurst merged 1 commit into
mainfrom
issue-585-batch-allocation

Conversation

@thomhurst

@thomhurst thomhurst commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

The warmed batch allocation comparison could include 56 B of native timer-lock initialization during its measured window. Warm each native timer queue's Lock through contention before the counters, and remove the test's NotInParallel attribute. Exact equality, finite send deadlines, buffered sends and parallel execution remain intact.

Closes #585

Deterministic diagnosis: forcing first timer-queue contention reproduces the actual comparison at 312,056 B versus 312,000 B on Linux x64/.NET 10.0.15 and macOS ARM64/.NET 10.0.14. The existing native profiler identifies one 24 B AutoResetEvent and one 32 B SafeWaitHandle, with zero callback failures; the separate native CancelAfter probe allocates 56 B on first contention and 0 B on the second. With the setup warmup, the forced batch comparison passes on both platforms; its callback report contains only the expected DI objects. All diagnostic outcomes, including failures, are retained. This establishes a deterministic cause of the same failure; it does not reconstruct the historical CI window. Callback sizes and thread-local counter totals are distinct measurements, and background TUnit allocations are retained rather than subtracted.

Native/existing reuse: CancellationTokenSource.CancelAfter, native TimerQueue/Lock lazy initialization, the existing DI allocation baseline, and tools/FrozenAllocationProfiler with its known-type fixture (8 tests passed). No timer implementation or allocation-accounting mechanism is duplicated. The setup helper reads only TimerQueue.Instances and SharedLock, then uses public locking operations; an unsupported runtime shape fails with an actionable message. This test-only runtime dependency is deliberate so native deadlines and the exact assertion stay exercised.

Validation: all 44 BatchPipelineTests passed on each of net10.0 and net11.0 on macOS ARM64 (88 total), and all 44 passed on Linux x64/.NET 10.0.15. Forced before/after controls and native profiler fixture passed their expected outcomes. git diff --check passed; full diff reviewed for correctness, reuse and efficiency. No benchmark needed: production per-message cost unchanged, 0 B added. No docs impact: only test warmup/parallelism changes; no library API or observable behavior changes.

Validation evidence: /Users/tom/git/Relayer-evidence/pr-587/1ac29a23991b3f4b9464c0164126d380bd442d9b/. All 1,706 source, loaded-binary/runtime, profiler SDK, diagnostic and report entries were independently length/SHA-256 checked against their originals and read back against inventory.json (SHA-256 a3f56ca232d41176f6f6279d42b84ee6c0416f3d0bf7b1a630948148d940c8ef). Linux runtime bytes were also checked against SHA-256 output from the immutable runtime image. Local evidence is retained while the PR is open. Historical input evidence remains under #585’s existing retained location.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 08c60455-7279-4918-9d45-09cc7a86d37a
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions

Copy link
Copy Markdown

Reviewed the head of #587 (test-only change: TimerQueueWarmup.cs plus a call and [NotInParallel] removal in BatchPipelineTests).

Findings: none blocking.

  • Correctness: The warmup forces contention on each native timer queue's shared Lock before GetAllocatedBytesForCurrentThread is read. That is the one-time lazy allocation the PR describes. The owner thread holds the lock until the caller is observed waiting, with a 10 s bounded spin, so a failed warmup throws rather than hanging. The warmup is placed before the measured window, and the exact-equality assertion is unchanged.
  • Parallelism: Removing [NotInParallel] follows AGENTS.md, which allows it only for tests that measure process-wide state. The counter here is per-thread, and the lazy lock state is warmed once and is process-wide. Other tests' allocations on other threads therefore don't enter the window.
  • Fragility (non-blocking): The helper reflects over private BCL internals (TimerQueue.Instances and SharedLock). It fails with an actionable message on an unsupported runtime shape, which matches the "fail early" rule. It is test-only, so the no-reflection rule for the per-message path doesn't apply. If a future runtime renames these members, the test fails loudly rather than silently passing. The PR notes net10 and net11 both pass.
  • Scope: The call is guarded by bufferedSends. The non-buffered argument presumably doesn't use CancelAfter deadlines, and the PR shows both variants passing.
  • Docs and perf: No library or per-message change, and no docs impact. The PR states this.

The change is sound and keeps the allocation test strict.

@thomhurst

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T08:05:36.024641Z 1ac29a2 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@thomhurst

Copy link
Copy Markdown
Owner Author
Follow-up #588 records the analogous throttles in the separate direct-send and overlapping-send allocation comparisons, pending this shared setup helper. The present PR remains scoped to the deterministic batch comparison. Claude’s current-head review is clear; Codex review was requested.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 1ac29a2399

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@thomhurst

Copy link
Copy Markdown
Owner Author
Both required reviewers cleared head 1ac29a2. Rechecked all review surfaces: no findings or threads outstanding. Before promotion, independently reverified all 1,706 archived entries against their originals for length and SHA-256; all match. Evidence remains at the location in the PR body, with inventory SHA-256 a3f56ca232d41176f6f6279d42b84ee6c0416f3d0bf7b1a630948148d940c8ef. No code changed and no tests rerun.

@thomhurst
thomhurst marked this pull request as ready for review November 13, 2026 08:04
@thomhurst
thomhurst enabled auto-merge (squash) November 13, 2026 08:04
@thomhurst
thomhurst merged commit d3e84b0 into main Nov 13, 2026
21 checks passed
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.

Attribute extra 56 B in buffered batch allocation comparison

1 participant