Skip to content

perf(net): index sparse arrivals and retire shared gaps together - #6287

Merged
kixelated merged 7 commits into
mainfrom
quest/m1/release-perf/sparse-gaps
Oct 23, 2026
Merged

kixelated merged 7 commits into
mainfrom
quest/m1/release-perf/sparse-gaps

Conversation

@kixelated

@kixelated kixelated commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The live-arrival ledger moves and checks every retained run on each sparse arrival. Gap retirement repeatedly splits the per-reader delivery record even when many gaps share one successor's stale verdict. Both add accidental size-dependent work to the track and subscription-tail consumers.

Approach

  • Index accounted runs by sequence and gap age. Splitting, merging, demand changes, and expiry preserve both indices. In-order arrivals extend the existing run without reallocating either index. An age index also avoids rescanning younger gaps when one older gap expires per arrival.
  • Sample the clock once and retire the last delivered run below the successor supplying the verdict, using one split per shared successor. Keep later gaps whose successor remains within budget.
  • Extend the existing nightly track benchmark with track_sparse_expire, additional flush sizes, and profiling boundaries. Add age-index invariant and edge tests for demand reordering, split/merge/remove, leading runs, grace changes, steady individual expiry, and partial wall-clock batches.
  • Settled: a flush costs O(log gaps + retired entries) per shared successor. Each retired entry must be freed exactly once, so the batch is already amortized optimal; a representation that hides that reclamation would widen scope for no measured benefit. The release-perf epic now records track_gap_flush as accepted, and this PR retires quest/m1/release-perf/sparse-gaps.md.

Benchmarks

Callgrind 3.27.1, Rust 1.98.1, --profile profiling (fat LTO, line tables, symbols), re-run after merging b8bb6730b7. Base is that origin/main with this branch's benchmark file, so both builds run the identical fixture. One --bench --test --exact iteration collects only *read_pair, *Expiring*arrive, or *GapFlush*flush.

Workload Gaps main this PR Change
track_sparse_read/timed 16 31,577 32,683 +3.5%
track_sparse_read/timed 256 42,333 36,378 -14.1%
track_sparse_read/timed 4096 268,694 43,270 -83.9%
track_sparse_read/untimed 16 26,301 27,874 +6.0%
track_sparse_read/untimed 256 36,531 30,578 -16.3%
track_sparse_read/untimed 4096 261,034 35,598 -86.4%
track_sparse_expire 16 16,109 17,081 +6.0%
track_sparse_expire 256 23,806 18,917 -20.5%
track_sparse_expire 4096 119,482 23,553 -80.3%
track_gap_flush 16 39,698 26,214 -34.0%
track_gap_flush 256 441,552 49,304 -88.8%
track_gap_flush 4096 9,086,608 463,527 -94.9%

At 16 gaps, index maintenance adds 3.5 to 6% to a read pair and to expiry. These are steady-state counts: both builds warm the same initial cache-queue capacities before collection, and the expiring workload warms two arrivals because the eviction queue trails the arrival queue by one entry. Cold queue growth still occasionally copies O(cached groups) entries; this PR neither fixes that amortized allocation cost nor claims it is logarithmic per operation.

Impact

  • Public API: none. Gap ages, grace changes, late arrivals, and subscriber retirement semantics remain covered by existing and new tests. The private ledger adds one age-index entry per accounted run.
  • Wire: none.

Alternatives

A vector plus a cached earliest deadline avoids a scan while nothing is due, but still scans every younger gap when deadlines expire singly. The ordered age index handles that workload without a full walk.

Validation

  • Merged origin/main with no textual conflicts. Main's new Ledger::end (moq-dev/moq#6111) still read the old vector, so the merge commit ports it to the map.
  • just rs test -p moq-net after the merge: 3,007 passed, 11 skipped.
  • just check origin/main: Rust lint/docs/wasm and quest pass; the unchanged Nix runner-image build fails because this host denies /proc/self/uid_map during systemd-repart.
  • quest check --base origin/main --branch quest/m1/release-perf/sparse-gaps passes.

Follow-ups

None new. The moq-cli late-stats integration failure seen in the first round reproduces on base (moq-dev/moq#6281) and is unrelated.

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

@kixelated kixelated changed the title Sparse gaps perf(net): index sparse gap arrivals and batch gap retirement Oct 22, 2026
@kixelated kixelated changed the title perf(net): index sparse gap arrivals and batch gap retirement perf(net): index sparse arrivals and retire shared gaps together Oct 22, 2026
Co-Authored-By: GPT-6 <noreply@openai.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Checkpoint pushed with the indexed ledger, successor-batched retirement, edge coverage, and nightly benchmark sweeps. At 4096 retained gaps, measured steady-state instructions fall 87.1% for a sparse read pair, 84.1% for individual expiry, and 94.9% for a full flush. Public API and wire impact: none.

Keeping this draft for the explicit complexity decision: accept O(log gaps + retired entries) per shared successor (recommended), or require logarithmic reclamation of the complete retired batch and broaden the representation design. The quest preserves its original Goal pending that choice. Validation limits are recorded: 2918 moq-net tests pass; 7960 affected tests pass with the known CLI late-stats failure; the local gate cannot build the unchanged runner image under this host's namespace restriction.

(Written by GPT-6)

kixelated and others added 2 commits October 22, 2026 14:32
A shared verdict retires its gaps in O(log gaps + retired entries). Each
retired entry is freed exactly once, so the batch is amortized optimal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review October 22, 2026 21:56
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 20 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ 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: 46f32288-a202-4f93-8bf8-361d37f422f4
📥 Commits

Reviewing files that changed from the base of the PR and between 8ee3c80 and 86097a0.

📒 Files selected for processing: 6
  • quest/m1/release-perf/README.md
  • quest/m1/release-perf/sparse-gaps.md
  • rs/moq-net/benches/track.rs
  • rs/moq-net/src/ledger.rs
  • rs/moq-net/src/model/delivered.rs
  • rs/moq-net/src/model/track.rs
  • 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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T04:19:15.300373Z 86097a0 New commits
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 53efed87c7

ℹ️ 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".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated added this pull request to the merge queue Oct 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 23, 2026
# Conflicts:
#	quest/m1/release-perf/README.md
@kixelated
kixelated added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 23, 2026
# Conflicts:
#	quest/m1/release-perf/README.md
@kixelated
kixelated added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit 49e8eb0 Oct 23, 2026
10 checks passed
@kixelated
kixelated deleted the quest/m1/release-perf/sparse-gaps branch October 23, 2026 07:06
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.

1 participant