Repository navigation
Check inline whether a VM's stack may shrink, so a VM call skips shrink when it cannot - #48
Merged
Merged
Conversation
…nk when it cannot Since the stack shrink was added, every VM call ran shrink's full check, about 35 instructions, and VM.leave was no longer inlined: 47 more instructions per call into a private VM. shrink is now an inlined guard that runs the full check only when the stack or frames are past the pool's bounds or a shrink is counting down; otherwise the check could only reset a counter that is already zero. A call into a private VM goes from 828 to 803 instructions.
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.
The new benchmark run in #47 showed a call into a private
VMabout 5 ns slower than in v0.4.0. Counting instructions per call (the slope between 10M and 30M calls underperf stat) traced it to 5a734e0 in #40, which went from 781 to 828 instructions per call. That commit madeVM.leavecallshrinkafter every call. Two costs came with it:shrinkran its full check even when there was nothing to shrink: a stack frame, twomaxcomputations, and the stack and frame comparisons, about 35 instructions.VM.leaveno longer fit the inlining budget, so every call also paid for a call intoleave.shrinkis now a small guard that the compiler inlines, with cost 77 against a budget of 80. It runs the full check, nowshrinkCheck, only when the stack or the frames are past the pool's bounds, or a shrink is already counting down (quietChecks != 0). In every other case the full check could only setquietChecksto 0, which it already is, so nothing changes in behaviour.Renewandcollectgarbageuse the same guard.BenchmarkAPICallPrivateCalls through a shared
Scriptdon't go throughVM.leaveand are unchanged (924 instructions).The remaining 22 instructions are the call into
VM.leaveand the guard itself. Getting them back would mean moving the check intoreset, which every other path would then pay for, so I didn't.TestDeepStackShrinkscovers the guard: it fails if the guard never lets the full check run.