Repository navigation
perf(jit): stock array bins per length class - #314
Merged
Merged
Conversation
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>
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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[]i32of 1 to 5 code points, so they took the slow path (a callout) on about 500 of 512 allocations per Run.jit.Classes = 8bins per type. Classc < 7holds arrays of lengthc. The last class holds one exact length ≥ 7, as a type's bin did before, keeping thechangeslimit andwide. A struct type uses class 0.reserve(arm64):Bins + t*Classes*SizeofBin;class = length <u 7 ? length : 7(CMPI+CSEL), plusMADD class*24;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).fillkeeps 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.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.go test ./interp ./internal/...,make check(pre-commit) andgit diff --check: pass.jit-internals.md(Reserve,Context.Bins, slow path).🤖 Generated with Claude Code