Skip covariant store checks when populating exact JsValue arrays#2683
Merged
Conversation
lahma
enabled auto-merge (squash)
July 14, 2026 07:15
JsValue is not sealed, so every args[i] = value store into a JsValue[] pays a runtime stelemref covariance check - measured at ~1.4% of program time on call-heavy workloads, 62% of it from call-argument population. Add Arguments.WriteNoTypeCheck (explicit bounds check + ref write via MemoryMarshal.GetArrayDataReference on net8+) for arrays that are provably exact JsValue[] - freshly allocated or rented from JsValueArrayPool, whose factories only create such arrays - and use it in the interpreter's argument-building loop. RegExp.Replace functional-replace paths also drop a List<JsValue> + ToArray() per match in favor of exact-sized arrays. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
lahma
force-pushed
the
perf-stelemref-arg-stores
branch
from
July 14, 2026 07:33
2526e0f to
5da3cf1
Compare
This was referenced Jul 15, 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
JsValueis not sealed, so everyarray[i] = valuestore into aJsValue[]pays a runtime covariant-store check (CastHelpers.StelemRef_Helper) — ETW-measured at ~1.4% of program time on call-heavy workloads, 62% of it from call-argument population.Adds
Arguments.WriteNoTypeCheck— explicit bounds check plus a ref write viaMemoryMarshal.GetArrayDataReferenceon net8+ (plain store on older TFMs), with aDebug.Assertand a documented exactness precondition — and uses it where the array is provably exactlyJsValue[]: the interpreter's argument-building loop (ExpressionCache.BuildArguments, arrays freshly allocated or rented fromJsValueArrayPool, whose factories only create exact arrays — verified) andRegExp.Replace's functional-replace paths, which also drop aList<JsValue>+ToArray()double allocation per match in favor of exact-sized arrays.Orthogonal to argument pooling/lifetime (which stays on
JsValueArrayPoolwith return-after-call semantics) — this changes only the store instruction.Benchmarks (default jobs, adjacent A/B on latest main)
Gates
🤖 Generated with Claude Code