Inline small block-env slot reset#2420
Merged
Merged
Conversation
The cached block-environment reset path used SlotTemplates.AsSpan().CopyTo to copy the binding template into the live slot array on every iteration of let/const-bearing loops. For typical block scopes (1-3 bindings — e.g. the stopwatch-modern body's `const z, ms, rn`) the Span construction + generic CopyTo overhead is comparable to the work itself. Move the copy into a small static helper with AggressiveInlining and a hand-rolled <=4-element loop. The JIT can unroll this and avoid the intermediate Span. Larger block scopes still go through CopyTo. stopwatch benchmark (clean): within noise of Change 3 — confirms no regression. Cumulative baseline -> Change 6 (clean run, low std-dev): Execute (var): 265 ms -> 205 ms (-23%) Execute_ParsedScript:386 ms -> 216 ms (-44%) Execute (let): 458 ms -> 247 ms (-46%) Execute_ParsedScript:443 ms -> 244 ms (-45%) Allocations: 71 MB -> 38.5 MB (-46%) 98567 test262 + 2861 Jint.Tests pass; 0 regressions. (Earlier transient 2-4 failures on decodeURI/A2.5_T1 were timeouts under concurrent machine load — these tests do 1.3M-iteration byte-range loops and are load-sensitive; pass cleanly when isolated.) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
lahma
enabled auto-merge (squash)
April 26, 2026 05:43
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
Last in the perf series. The cached block-environment reset path in
JintBlockStatement.ExecuteBlockresets the slot array on every iteration oflet/const-bearing loops viaSlotTemplates.AsSpan().CopyTo(_slots). For typical block scopes (1-3 bindings — e.g.const z, ms, rninstopwatch-modern.js) the Span construction + genericCopyTooverhead is comparable to the work itself.This PR moves the copy into a tiny static helper with
[MethodImpl(AggressiveInlining)]and a hand-rolled<= 4-element loop. The JIT can unroll this and avoid the intermediateSpan. Larger block scopes still go throughCopyTo.Benchmark (stopwatch.js, fresh back-to-back)
Ryzen 9 5950X / .NET 10.0.7. Both runs taken back-to-back on the same session. The
Execute_ParsedScript (let)baseline run had a bimodal outlier (one iteration at ~340ms pulling the mean to 287ms with StdDev 60ms; median was 246.5ms) — the more honest baseline for that case is the median, against which C6's mean of 243.5ms is also flat.*median, baseline run had a bimodal outlier
So: essentially flat in measurement. The change is justified on code-path quality (avoids generic CopyTo overhead on a known-small array) rather than a chase-able number. Worth landing for the same reason as
[AggressiveInlining]markers elsewhere in this codebase: it expresses a hot-path intent that JIT can act on.Validation
Jint.Tests(net10.0): 2861 passed, 0 failed.Jint.Tests.Test262(net10.0): 98567 passed, 506 skipped, 0 failed.Stack context
Sixth and final perf change in the series:
(uint)i < (uint)lengthdoc + cleanups (merged)Cumulative measured impact across the series on
stopwatch.js: ~5% time reduction, ~46% allocation reduction (71 MB → 38.5 MB). The big wins were #2412 (cache fires for configurable properties) and #2413 (env pool, the bulk of the alloc reduction); #2416 / #2419 / this PR are smaller polish.🤖 Generated with Claude Code