Repository navigation
perf(interp): reuse generic array backing storage across resets - #192
Conversation
Every Run that built a generic array allocated a fresh backing slice, so a reused Interpreter paid the allocation again on each Reset even though the array header it was attached to was already being recycled. Reset now clears a reclaimed generic array's backing storage instead of dropping it, and ARRAY_NEW/ARRAY_NEW_DEFAULT reuse that storage when the requested length fits. Semantics are unchanged: a reused backing is cleared to the element type's zero, and an array that escaped the run - detached by pop, or reclaimed before the reset - keeps its own storage and is never handed to a later run. The "resets generic array contents" Reset subtest went with it: the two subtests beside it, "preserves arrays detached by pop" and "preserves arrays reclaimed before reset", already assert both halves of that contract - the cleared elements and the non-reuse of an escaped header. BenchmarkMemory_AllocationGraph, Apple M4 Pro, darwin/arm64, Go 1.26.2, go test -run='^$' -bench=. -benchtime=300ms -count=3, median of three: default 5.64 us, 1024 B/op, 128 allocs/op -> 5.03 us, 0 B/op, 0 allocs/op threaded 4.99 us, 1024 B/op, 128 allocs/op -> 4.31 us, 0 B/op, 0 allocs/op jit 5.63 us, 1024 B/op, 128 allocs/op -> 5.00 us, 0 B/op, 0 allocs/op Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughGeneric array pooling now retains and clears backing storage during reset. A new sized constructor reuses that storage when possible. Generated and threaded allocation paths use the constructor directly. ChangesGeneric array pooling
Estimated code review effort: 2 (Simple) | ~15 minutes Merge Risk: ⚪ Minimal · up to The change reuses cleared generic-array backing storage while preserving independent storage for escaped arrays; no actionable merge-blocking risk remains after normal checks and review. Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.45.1)interp/threaded.goast-grep timed out on this file 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. Comment |
Split out of #191, which had accumulated several unrelated changes. This one is independent of the JIT work in that stack and can land on its own.
Problem
Every
Runthat built a generic array allocated a fresh backing slice. A reusedInterpreterpaid that allocation again after eachReset, even though the array header it was attached to was already being recycled.Change
Resetnow clears a reclaimed generic array's backing storage instead of dropping it, andARRAY_NEW/ARRAY_NEW_DEFAULTreuse that storage when the requested length fits.Semantics are unchanged:
The
resets generic array contentsResetsubtest went with it. The two subtests beside it,preserves arrays detached by popandpreserves arrays reclaimed before reset, already assert both halves of that contract: the cleared elements and the non-reuse of an escaped header.Results
BenchmarkMemory_AllocationGraph, Apple M4 Pro, darwin/arm64, Go 1.26.2,go test -run='^$' -bench=. -benchtime=300ms -count=3, median of three:The zero-allocation result was re-confirmed in a fresh run on this branch.
Test plan
go test -race ./...make check-generatedgo vet ./...BenchmarkMemory_AllocationGraphre-measured on branchRefs #164
🤖 Generated with Claude Code
Summary by CodeRabbit