perf(vm): remove the runLoop hop; make leaveFrame parameter-free - #730
Open
mparrett wants to merge 2 commits into
Open
perf(vm): remove the runLoop hop; make leaveFrame parameter-free#730mparrett wants to merge 2 commits into
mparrett wants to merge 2 commits into
Conversation
This was referenced Aug 12, 2026
…-free Two structural notes from #719's review, together because they meet at runLoopAttr: runLoop was a dispatcher too big to inline (cost 144 vs budget 80), so the entry path paid Run -> runChain -> runLoop -> runLoopInner — one real call more than needed on every host->VM entry and error-resume iteration. Hoist the allocAttrEnabled gate into runChain's loop and call runLoopAttr/runLoopInner directly; runLoop goes away. leaveFrame took a *Frame it never read, and the doc comment leaned on that: in OP_RETURN there is a window after ReleaseFrame(child) where state.current still points at the pooled frame, so the first real use of the parameter would be a use-after-release. Drop the parameter — the invariant is now structural, and runLoopAttr's defer no longer needs a closure. Interleaved go-bench medians (N=6, vs #719 head): FrameDispatch 0.94x, FuncInvoke/Closure 0.97x, Direct 1.00x — flat to slightly better. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The default configuration's panic path had no test: with LG_ALLOC_ATTR unset Run is deliberately defer-free and a Go panic leaks the chain's pooled frames to GC (pre-#645 parity), but nothing pinned that intent — a change reintroducing a must-release-on-panic invariant would pass the suite silently. Panic a raw (unwrapped) callable inside a descended frame and assert the panic value survives and the pool sees the intended behavior: leak-to-GC with attribution off, exactly-once release via runChainProtected with it on. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
mparrett
force-pushed
the
perf/vm-dispatch-followups
branch
from
August 12, 2026 19:50
37afd8f to
b680b49
Compare
mparrett
marked this pull request as ready for review
August 14, 2026 23:09
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.
Draft until the stack ahead of it settles; I'll add
perf-repeatfor an EPYC adjudication once the queue is quiet.Carries the three low-severity notes from #719's review as a stacked PR, so #719 merges as reviewed and its perf-repeat baseline stays put.
runChain.runLoopwas a dispatcher too big to inline (cost 144 exceeds budget 80), so the entry path paidRun → runChain → runLoop → runLoopInner— one non-inlined call more than needed on every host→VM entry and every error-resume iteration. The gate is now hoisted out ofrunChain's loop and callsrunLoopAttr/runLoopInnerdirectly;runLoopis gone.leaveFrame's parameter. It took a*Frameit never read, and inOP_RETURNthere is a window afterReleaseFrame(child)wherestate.currentstill points at the pooled frame — the first real use of the parameter would have been a use-after-release. With no parameter the invariant is structural, andrunLoopAttr's defer sheds its closure.LG_ALLOC_ATTRunset,Runis deliberately defer-free and a Go panic leaks the chain's pooled frames to GC (pre-vm: make direct bytecode calls non-recursive with an explicit frame chain #645 parity) — previously documented but untested. The new test panics a raw (unwrapped) callable inside a descended frame and asserts the panic value survives and the pool sees the intended behavior in both configurations: leak-to-GC with attribution off, exactly-once release viarunChainProtectedwith it on.Measured (interleaved go-bench medians, N=6, vs #719's head):
FrameDispatch0.94×,FuncInvoke/Closure0.97×,Direct1.00× — flat to slightly better, matching the review's own bench of the fold.Verified:
pkg/vm,pkg/rt,pkg/genmanifest,test/suites;go test -race ./pkg/vm; both suites again withLG_ALLOC_ATTR=1; the new test passes in both configurations; linux, plan9, js/wasm builds.