Unboxed fast path for plain numeric assignment (s = a op b)#2550
Merged
Conversation
Compound numeric assignment (s += i) already computes on raw doubles via an unboxed slot path, but plain assignment of a numeric binary expression (s = s + i, d = a - b) ran the right-hand side through the boxed binary path and stored a materialized JsNumber, so a function-local numeric loop allocated a transient number on most iterations. Add a narrow, slot-gated discard fast path for `lhs = a op b` where lhs is a slot-stored number, each operand is a number-slot identifier or numeric literal, and op is + - / %. Operands are read as raw doubles (JintIdentifierExpression.TryReadNumber -> TryGetNumberSlot), computed on double, and stored via SetNumberSlot. Eligibility is decided once, eagerly, from the AST so anything that isn't this exact shape keeps its exact current code path (HasDiscardFastPath gates the routing); operand reads are pure slot reads, so declining after a partial read has no observable effect. Multiplication is intentionally excluded: the boxed path multiplies small integers as integers and yields +0 for 0 * negative, while raw-double multiplication yields the spec-correct -0 — including it would change observable behaviour. For + - / % the two paths are identical, so this is a pure optimization (a differential over the integer grid, compared with Object.is, reports 0 divergences). PlainNumericAssignBenchmark (fresh engine, default job, .NET 10, same-runtime A/B): SumAssign (s = s + i): 90.9 ms / 60.7 MB -> 58.7 ms / 30.2 MB (-35% time, -50% alloc) Mixed (a = a + b; d = a - b): 160.1 ms / 90.6 MB -> 88.0 ms / 30.2 MB (-45% time, -67% alloc) DivAssign (s = s / h): 157.9 ms / 60.7 MB -> 137.1 ms / 60.7 MB (-13% time) Guards (dromaeo-object-array, stopwatch): flat allocation, time within thermal noise; the member-assignment path is unchanged (HasDiscardFastPath=false). Jint.Tests 3138/0, Test262 0 new failures. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
lahma
force-pushed
the
okojo-ws5-unboxed-assign
branch
from
June 28, 2026 08:44
8de03ec to
8d93bb8
Compare
lahma
enabled auto-merge (squash)
June 28, 2026 08:45
This was referenced Jul 6, 2026
This was referenced Jul 13, 2026
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
Compound numeric assignment (
s += i) already has an unboxed slot fast path that computes on raw doubles. Plain assignment of a numeric binary expression —s = s + i,d = a - b— did not: it ran the right-hand side through the boxed binary path (JsNumber.Create) and stored a materializedJsNumber, so a function-local numeric loop allocated a transient number on most iterations.This adds a narrow, slot-gated discard fast path for
lhs = a op bwhere:lhsis a slot-stored number binding (a function local), anda,bis a number-slot identifier or a numeric literal, andop ∈ { +, -, /, % }.It reads the operands as raw doubles (
JintIdentifierExpression.TryReadNumber→DeclarativeEnvironment.TryGetNumberSlot), computes ondouble, and stores unboxed (SetNumberSlot) — mirroring the existingTryCompoundUnboxedpath.Behaviour-preserving. Eligibility is decided once, eagerly, from the AST (
HasDiscardFastPath), so anything that isn't this exact shape — member/element targets, non-numeric or non-slot operands, operator overloading, generators/async — keeps its exact current code path (no added per-evaluation cost). Operand reads are pure slot reads (never getters), so declining after a partial read has no observable effect.Multiplication is intentionally excluded. The boxed binary path multiplies small integers as integers and yields
+0for0 * negative, whereas raw-double multiplication yields the spec-correct-0; including it would change observable behaviour. For+ - / %the two paths produce identical results, so this stays a pure optimization. A differential test over the integer grid [-40,40]×[-13,13] (compared withObject.is, i.e. distinguishing±0andNaN) reports 0 divergences for all four enabled operators.Benchmark
New
Jint.Benchmark/PlainNumericAssignBenchmark(fresh-engine, default BDN job, .NET 10, Ryzen 9 5950X, same-runtime worktree A/B):s = s + i)a = a + b; d = a - b)s = s / h)(
SumAssign's residual allocation is the loop conditioni < Nre-boxing the counter, which this change does not touch.)Regression guards (EngineComparison
Jint_ParsedScript):dromaeo-object-array(the path the earlier broad unboxed-double attempt regressed) andstopwatchshow flat allocation and time within run-to-run thermal noise. Member-assignment-heavy code (object-array) takes the unchangedHasDiscardFastPath=falsepath, so it cannot regress structurally.Correctness
+ - / %.dotnet test Jint.Tests: 3138 passed, 0 failed.dotnet test Jint.Tests.PublicInterface: 79 passed, 0 failed.🤖 Generated with Claude Code