Skip to content

perf(heap): decide the write barrier with one Gen2 lookup - #5410

Closed
harivansh-afk wants to merge 1 commit into
brr/nv0-wb-2-lockfreefrom
brr/nv0-wb-3-one-lookup
Closed

harivansh-afk wants to merge 1 commit into
brr/nv0-wb-2-lockfreefrom
brr/nv0-wb-3-one-lookup

Conversation

@harivansh-afk

Copy link
Copy Markdown
Collaborator

TLDR

Stacked on #5409 (wb-2). Only Gen2 has cards, because minor collections trace Gen0 and Gen1 together. mark_card_for_ptr already ignored every other container. The barrier still classified both sides fully: up to four chunk scans, then a fifth in mark_card_for_ptr to find the card. Most containers are young, and a young container is the worst case: every scan runs to the end and misses.

How

  • write_barrier: look up the container's Gen2 location first. If it's in Gen2 and the value isn't, mark the card at that location. A young container costs one Gen2 scan.
  • conservative_write_barrier calls mark_card_for_ptr directly.
  • Small helpers: locate_in_gen2, mark_card_at.
  • The same cards are marked as before: container in Gen2 and value in CompileTime, Gen0 or Gen1. wb-1's matrix pins this.

Results (wb-2 + wb-3 vs #5264 at 19f2ae2328, 10 interleaved rounds)

workload Spark native Spark bytecode x86 native x86 bytecode
richards-50 1.57× 1.29× 1.13× 1.19×
array-build-sum-100k 1.32× 1.09× 1.08× 1.09×
grid-alloc-1000x100 1.30× 1.09× 1.11× 1.13×
merge-sort-20k 1.07× 1.05× 1.08× 1.33×
allocation-high-retention 1.05× 1.04× 1.02× 1.14×
k-nucleotide-25k 1.03× 1.06× 1.02×* 1.03×
cycles-into-live 1.02× 1.02× 1.01× 1.03×
live-walk / json-parser-15 1.00× 1.00–1.02× 1.01×* / 1.00× 1.00–1.03×

* 20-trial rerun; the first 10-trial run read 0.97× / 0.96× with a ~25% trial spread.

  • Spark: aarch64, Cortex-X925, pinned core. x86: Freestyle bench-x86-v1.
  • x86 gains less because an atomic there is one inline lock instruction, not an outlined call.
  • Profile, native richards on Spark: the lock atomics went from ~31% to ≤0.2%, and generation_of no longer appears.
  • A constant-time Gen2 lookup (wb-4) is parked: what's left of the scan doesn't show in the profile while Gen2 is a few chunks.

Measurements: instrumentation/measurements/2026-10-25-write-barrier-ab-{spark,x86,x86-rerun}/.

Minor collections trace Gen0 and Gen1 together, so a card is only ever
needed for a Gen2 container that receives a reference from outside Gen2;
mark_card_for_ptr already ignored every other container. The barrier still
classified both sides fully: up to four chunk scans, then a fifth in
mark_card_for_ptr to find the card.

Check the container's Gen2 location first and reuse it for the card. A young
container, the common case, now costs one Gen2 scan. Same cards are marked
as before: container in Gen2 and value in CompileTime, Gen0 or Gen1.
conservative_write_barrier calls mark_card_for_ptr directly for the same
reason.
@vercel

vercel Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
developer-docs Ready Ready Preview Oct 25, 2026 9:43pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.

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

@github-actions

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@github-actions

Copy link
Copy Markdown

Binary size checks failed

❌ 2 violations · ✅ 1 passed

⚠️ Please fix the size gate issues or acknowledge them by updating baselines.

Artifact Platform File Gzip Gated on Baseline Delta Status
✅ baml-cli Linux 🔒 64.1 MB 27.3 MB file 73.1 MB -9.0 MB (-12.3%) OK
❌ packed-program Linux 🔒 41.4 MB 16.9 MB file 29.2 MB +12.2 MB (+41.9%) FAIL
❌ bridge_wasm WASM 27.4 MB 🔒 8.0 MB gzip 5.7 MB +2.4 MB (+41.8%) FAIL

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.

Details & how to fix

Violations:

  • packed-program (Linux) file_bytes: 41.4 MB exceeds limit of 30.1 MB (exceeded by +11.3 MB, policy: max_file_bytes)
  • packed-program (Linux) file_delta_pct: +41.9% exceeds limit of 3.0% (exceeded by +38.9pp, policy: max_delta_pct)
  • bridge_wasm (WASM) gzip_bytes: 8.0 MB exceeds limit of 5.9 MB (exceeded by +2.2 MB, policy: max_gzip_bytes)
  • bridge_wasm (WASM) gzip_delta_pct: +41.8% exceeds limit of 3.0% (exceeded by +38.8pp, policy: max_delta_pct)

Add/update baselines:

.ci/size-gate/wasm32-unknown-unknown.toml:

[artifacts.bridge_wasm]
file_bytes = 27365333
gzip_bytes = 8029812

.ci/size-gate/x86_64-unknown-linux-gnu.toml:

[artifacts.packed-program]
file_bytes = 41368224
gzip_bytes = 16867680

Generated by cargo size-gate · workflow run

@harivansh-afk

Copy link
Copy Markdown
Collaborator Author

Closing: superseded by the shared-runtime consolidation tracked from #5566. Branch kept for reference.

This branch was successfully deployed

1 active deployment
Preview – developer-docs — 00a23ffa Deployed Oct 25, 2026 by vercel[bot]
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