Repository navigation
Update the progress counter inline in TurboFan code when replaying - #213
Merged
Merged
Conversation
Ports replayio/chromium-v8#369. Optimized code called into the VM at every progress bytecode when replaying, so that it could be deoptimized when the target progress was reached. The inline update's call at the target has had a lazy deoptimization point and the function's context since #194/#195, which is all that what runs there needs: pausing, setting breakpoints and changing instrumentation discard the code while the call is on the stack, and the frame resumes in the interpreter after the progress bytecode, as it does after the VM call. Baseline code already updates the counter inline when replaying (#211). Progress assertions still need the VM call. Unlike Chromium, the choice doesn't also depend on gRecordReplayCheckProgress, and optimized code doesn't run progress checks, as before when recording: - Checks are enabled while events are disallowed on the main thread, and Compiler::CompileOptimized disallows them (#142). TurboFan compiles on the JS thread when recording or replaying, so testing the flag when compiling made every optimized function use the VM call: recording a TurboFan-hot loop took 4.8 s instead of 0.71 s. - Testing it when the code runs, as baseline code does, made recording the same loop 36% slower (976 ms vs 715 ms, 5 of 5 runs). Replaying a recording of that loop (200M iterations of a small inlined function) took 21.1 s on average instead of 32.9 s (4 runs each), and recording it takes as long as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 6, 2026
Add IncrementAndCheckProgressCounter IR opcode to the optimizing compiler pipeline: opcodes, simplified operators, bytecode graph builder, effect control linearizer, memory optimizer, typer, lowering, and verifier. The node takes the frame state for after the progress bytecode, which the call at the target progress lazily deoptimizes to, and the function's context, because what runs at the target can run JS. With neither, the recording's own inspector session asked for a break near the heap limit while the call was on the stack and V8 crashed in OptimizedFrame::GetFunctions on the missing deoptimization data, then in Debug::OnDebugBreak on the missing context. The node is not eliminatable, and the graph builder CHECKs that an eager checkpoint is still needed after the progress bytecode, so an eager deoptimization cannot resume before it and count that progress twice. Optimized code only calls into the VM at every progress bytecode when progress is asserted; otherwise it increments the counter inline, both when recording and when replaying, and calls into the VM only at the target progress. Optimized code does not run progress checks: they are enabled while events are disallowed on the main thread, which they are while TurboFan compiles, so testing gRecordReplayCheckProgress at compile time would make every optimized function use the VM call, and testing it in the inline update instead costs too much. Sparkplug increments the counter inline as well, on x64 and arm64, and calls into the VM only at the target progress, or, unlike optimized code, whenever asserts or checks are enabled, which it tests when the code runs. The progress and instrumentation calls from baseline code now take the accumulator and return it rather than being wrapped in a SaveAccumulatorScope: setting a breakpoint discards the baseline code while such a call is on the stack, and the frame then resumes in the interpreter with the call's result as its accumulator. The BaselineAssembler helpers that only the previously disabled fast path used (AddPointer, ComparePointer, JumpIfCondition) are removed again. Date.now() lowers to a DateNow node that upstream marks eliminatable; when recording or replaying it counts as a write instead, so the checkpoint after it is not dropped as redundant and an eager deoptimization later in the function cannot resume before it and read the time again. Every time read is a recorded call, so optimized code has to read it exactly as often as the bytecode does. Rebase note: every progress bytecode must advance the counter exactly once, whichever tier runs it, and a call emitted at a progress or instrumentation site must preserve the accumulator and, in optimized code, carry the frame state for after the bytecode plus a context. A new upstream pass or operator property that eliminates, hoists or duplicates the progress node, or drops the checkpoint after it, breaks that, as does letting DateNow be treated as pure while recording or replaying. Includes later changes from #128, #187, #194, #195, #207, #211 and #213. Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-authored-by: Domi <Domiii@users.noreply.github.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 6, 2026
Add IncrementAndCheckProgressCounter IR opcode to the optimizing compiler pipeline: opcodes, simplified operators, bytecode graph builder, effect control linearizer, memory optimizer, typer, lowering, and verifier. The node takes the frame state for after the progress bytecode, which the call at the target progress lazily deoptimizes to, and the function's context, because what runs at the target can run JS. With neither, the recording's own inspector session asked for a break near the heap limit while the call was on the stack and V8 crashed in OptimizedFrame::GetFunctions on the missing deoptimization data, then in Debug::OnDebugBreak on the missing context. The node is not eliminatable, and the graph builder CHECKs that an eager checkpoint is still needed after the progress bytecode, so an eager deoptimization cannot resume before it and count that progress twice. Optimized code only calls into the VM at every progress bytecode when progress is asserted; otherwise it increments the counter inline, both when recording and when replaying, and calls into the VM only at the target progress. Optimized code does not run progress checks: they are enabled while events are disallowed on the main thread, which they are while TurboFan compiles, so testing gRecordReplayCheckProgress at compile time would make every optimized function use the VM call, and testing it in the inline update instead costs too much. Sparkplug increments the counter inline as well, on x64 and arm64, and calls into the VM only at the target progress, or, unlike optimized code, whenever asserts or checks are enabled, which it tests when the code runs. The progress and instrumentation calls from baseline code now take the accumulator and return it rather than being wrapped in a SaveAccumulatorScope: setting a breakpoint discards the baseline code while such a call is on the stack, and the frame then resumes in the interpreter with the call's result as its accumulator. The BaselineAssembler helpers that only the previously disabled fast path used (AddPointer, ComparePointer, JumpIfCondition) are removed again. Date.now() lowers to a DateNow node that upstream marks eliminatable; when recording or replaying it counts as a write instead, so the checkpoint after it is not dropped as redundant and an eager deoptimization later in the function cannot resume before it and read the time again. Every time read is a recorded call, so optimized code has to read it exactly as often as the bytecode does. Rebase note: every progress bytecode must advance the counter exactly once, whichever tier runs it, and a call emitted at a progress or instrumentation site must preserve the accumulator and, in optimized code, carry the frame state for after the bytecode plus a context. A new upstream pass or operator property that eliminates, hoists or duplicates the progress node, or drops the checkpoint after it, breaks that, as does letting DateNow be treated as pure while recording or replaying. Includes later changes from #128, #187, #194, #195, #207, #211 and #213. Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-authored-by: Domi <Domiii@users.noreply.github.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
pushed a commit
that referenced
this pull request
Nov 6, 2026
Add IncrementAndCheckProgressCounter IR opcode to the optimizing compiler pipeline: opcodes, simplified operators, bytecode graph builder, effect control linearizer, memory optimizer, typer, lowering, and verifier. The node takes the frame state for after the progress bytecode, which the call at the target progress lazily deoptimizes to, and the function's context, because what runs at the target can run JS. With neither, the recording's own inspector session asked for a break near the heap limit while the call was on the stack and V8 crashed in OptimizedFrame::GetFunctions on the missing deoptimization data, then in Debug::OnDebugBreak on the missing context. The node is not eliminatable, and the graph builder CHECKs that an eager checkpoint is still needed after the progress bytecode, so an eager deoptimization cannot resume before it and count that progress twice. Optimized code only calls into the VM at every progress bytecode when progress is asserted; otherwise it increments the counter inline, both when recording and when replaying, and calls into the VM only at the target progress. Optimized code does not run progress checks: they are enabled while events are disallowed on the main thread, which they are while TurboFan compiles, so testing gRecordReplayCheckProgress at compile time would make every optimized function use the VM call, and testing it in the inline update instead costs too much. Sparkplug increments the counter inline as well, on x64 and arm64, and calls into the VM only at the target progress, or, unlike optimized code, whenever asserts or checks are enabled, which it tests when the code runs. The progress and instrumentation calls from baseline code now take the accumulator and return it rather than being wrapped in a SaveAccumulatorScope: setting a breakpoint discards the baseline code while such a call is on the stack, and the frame then resumes in the interpreter with the call's result as its accumulator. The BaselineAssembler helpers that only the previously disabled fast path used (AddPointer, ComparePointer, JumpIfCondition) are removed again. Date.now() lowers to a DateNow node that upstream marks eliminatable; when recording or replaying it counts as a write instead, so the checkpoint after it is not dropped as redundant and an eager deoptimization later in the function cannot resume before it and read the time again. Every time read is a recorded call, so optimized code has to read it exactly as often as the bytecode does. Rebase note: every progress bytecode must advance the counter exactly once, whichever tier runs it, and a call emitted at a progress or instrumentation site must preserve the accumulator and, in optimized code, carry the frame state for after the bytecode plus a context. A new upstream pass or operator property that eliminates, hoists or duplicates the progress node, or drops the checkpoint after it, breaks that, as does letting DateNow be treated as pure while recording or replaying. Includes later changes from #128, #187, #194, #195, #207, #211 and #213. Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-authored-by: Domi <Domiii@users.noreply.github.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
pushed a commit
that referenced
this pull request
Nov 6, 2026
Add IncrementAndCheckProgressCounter IR opcode to the optimizing compiler pipeline: opcodes, simplified operators, bytecode graph builder, effect control linearizer, memory optimizer, typer, lowering, and verifier. The node takes the frame state for after the progress bytecode, which the call at the target progress lazily deoptimizes to, and the function's context, because what runs at the target can run JS. With neither, the recording's own inspector session asked for a break near the heap limit while the call was on the stack and V8 crashed in OptimizedFrame::GetFunctions on the missing deoptimization data, then in Debug::OnDebugBreak on the missing context. The node is not eliminatable, and the graph builder CHECKs that an eager checkpoint is still needed after the progress bytecode, so an eager deoptimization cannot resume before it and count that progress twice. Optimized code only calls into the VM at every progress bytecode when progress is asserted; otherwise it increments the counter inline, both when recording and when replaying, and calls into the VM only at the target progress. Optimized code does not run progress checks: they are enabled while events are disallowed on the main thread, which they are while TurboFan compiles, so testing gRecordReplayCheckProgress at compile time would make every optimized function use the VM call, and testing it in the inline update instead costs too much. Sparkplug increments the counter inline as well, on x64 and arm64, and calls into the VM only at the target progress, or, unlike optimized code, whenever asserts or checks are enabled, which it tests when the code runs. The progress and instrumentation calls from baseline code now take the accumulator and return it rather than being wrapped in a SaveAccumulatorScope: setting a breakpoint discards the baseline code while such a call is on the stack, and the frame then resumes in the interpreter with the call's result as its accumulator. The BaselineAssembler helpers that only the previously disabled fast path used (AddPointer, ComparePointer, JumpIfCondition) are removed again. Date.now() lowers to a DateNow node that upstream marks eliminatable; when recording or replaying it counts as a write instead, so the checkpoint after it is not dropped as redundant and an eager deoptimization later in the function cannot resume before it and read the time again. Every time read is a recorded call, so optimized code has to read it exactly as often as the bytecode does. Rebase note: every progress bytecode must advance the counter exactly once, whichever tier runs it, and a call emitted at a progress or instrumentation site must preserve the accumulator and, in optimized code, carry the frame state for after the bytecode plus a context. A new upstream pass or operator property that eliminates, hoists or duplicates the progress node, or drops the checkpoint after it, breaks that, as does letting DateNow be treated as pure while recording or replaying. Includes later changes from #128, #187, #194, #195, #207, #211 and #213. Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-authored-by: Domi <Domiii@users.noreply.github.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Ports replayio/chromium-v8#369. Optimized code called into the VM at every progress bytecode when replaying, so that it could be deoptimized when the target progress was reached. The inline update's call at the target has had a lazy deoptimization point and the function's context since #194/#195, which is all that what runs there needs: pausing, setting breakpoints and changing instrumentation discard the code while the call is on the stack, and the frame resumes in the interpreter after the progress bytecode, as it does after the VM call. Baseline code already updates the counter inline when replaying (#211).
Progress assertions still need the VM call. Unlike Chromium, the choice doesn't also depend on gRecordReplayCheckProgress, and optimized code doesn't run progress checks, as before when recording:
Replaying a recording of that loop (200M iterations of a small inlined function) took 21.1 s on average instead of 32.9 s (4 runs each), and recording it takes as long as before.