Skip to content

perf(jit): stock array bins per length class - #314

Merged
siyul-park merged 2 commits into
mainfrom
perf/tcache-classes
Nov 10, 2026
Merged

siyul-park merged 2 commits into
mainfrom
perf/tcache-classes

Conversation

@siyul-park

Copy link
Copy Markdown
Owner

Summary

Fixes #298. The native reserve kept one array length per type (jit.Bin.Len). A type allocated at several lengths stopped stocking after its second length change in an entry. string-build and string-compare build []i32 of 1 to 5 code points, so they took the slow path (a callout) on about 500 of 512 allocations per Run.

  • jit.Classes = 8 bins per type. Class c < 7 holds arrays of length c. The last class holds one exact length ≥ 7, as a type's bin did before, keeping the changes limit and wide. A struct type uses class 0.
  • reserve (arm64):
    • entry = Bins + t*Classes*SizeofBin;
    • for an array, class = length <u 7 ? length : 7 (CMPI + CSEL), plus MADD class*24;
    • then the existing N/CBZ and Len checks.
      A negative length compares huge, lands in the last class, and misses its Len. N is checked before Len, so an unset bin (Len −1) cannot match.
  • tcache: every per-type slice is now per-bin (n*Classes). fill keeps its signature and picks the bin. Learning, batching and the change limit work per bin as before.

Evidence

  • TestMachine_Lower: the array reserve cases (class bin, far offset) were red before the lowering changed.
  • TestWithThreshold "…lengths cycling 1..5…" equals threaded, with fewer than n/8 bridge exits: 141 of 2000, where it was nearly all 2000 before. The test was red before the change, because the old bin alternated and the ledger retired the loop's native code.
  • Two subtests were adjusted:
    • "alternates…" now uses lengths 7/8, since short lengths no longer alternate.
    • "refills … mid-loop" now compares live objects instead of HeapLen. With several bins, a cached slot left below a live slot can leave the heap a few slots longer than threaded's, bounded by the leftover bins. Live objects are identical.
  • Local A/B (6 × 300 ms): string-compare about −12% (132.5k → 116.5k ns). string-build was too noisy to call. binary-trees and n-body were unchanged. The CI report decides.
  • go test ./interp ./internal/..., make check (pre-commit) and git diff --check: pass.
  • Docs: jit-internals.md (Reserve, Context.Bins, slow path).

🤖 Generated with Claude Code

The native reserve kept one array length per type, so a type allocated
at several lengths stopped stocking after its second length change in
an entry and took the slow path on nearly every allocation
(string-build and string-compare build []i32 of 1 to 5 code points).

Each type now has jit.Classes bins: class c below the last holds arrays
of length c, and the last holds one exact length at or past it, as a
type's bin did before. The reserve picks the class with an unsigned
compare and a select, so a negative length still misses. Bin.Len and
the per-bin fill, learning and change limit are unchanged.

Fixes #298

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 002af089-425d-4808-978c-9f9fc743bf5f
  • 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

@siyul-park
siyul-park merged commit 89c5ad0 into main Nov 10, 2026
2 checks passed
@siyul-park
siyul-park deleted the perf/tcache-classes branch November 10, 2026 00:02
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.

perf(jit): array.new_default misses the tcache when lengths vary

1 participant