From 8369dd372b19ebfa0fee7dc8f72eac390d9a644e Mon Sep 17 00:00:00 2001 From: Marko Lahma Date: Thu, 9 Jul 2026 10:25:27 +0300 Subject: [PATCH] Add dense-array append fast path for computed-index writes `m[i] = v` at exactly the current length - the array-building pattern of dromaeo-3d-cube's MMulti/VMulti kernels (result arrays start empty and every write is an append) - previously fell through the overwrite-only dense fast path into the full PutValue -> Set -> SetIndexValue pipeline per element. ArrayInstance.TryAppendDense appends in place: same doubling growth policy as WriteArrayValueUnlikely's dense arm, length bumped via SetLengthValue. It declines (deferring to the spec path and its errors) for non-append indices, non-extensible arrays, non-writable or materialized-non-default length, sparse mode and the dense cap. The assignment fast path probes it only after the existing overwrite arm misses, so overwrite-dominant workloads pay one predicted-false branch on the miss path only. ElementAccessBenchmark A/B (default job, adjacent runs; AppendWrite row added by this change - fresh arrays, four appends each): | row | before | after | | |-----------------|-----------|-----------|------------| | AppendWrite | 44.78 ms | 40.16 ms | -10.3% | | Write | 112.74 ms | 113.95 ms | flat* | | Read | 111.02 ms | 114.07 ms | flat* | | ReadModifyWrite | 199.84 ms | 187.93 ms | -3..6%* | | ChainedRead | 158.14 ms | 153.95 ms | -2.6%* | *sign-mixed process-mode noise, resolved via --launchCount 5 (medians); allocations byte-identical on every row. Tests pin append/lazy-array/a[a.length] shapes, strict-mode TypeErrors for preventExtensions/non-writable-length/frozen, hole-fill and out-of-order writes keeping spec behavior, and element integrity across capacity growth. Co-Authored-By: Claude Fable 5 --- Jint.Benchmark/ElementAccessBenchmark.cs | 18 ++++ Jint.Tests/Runtime/ArrayAppendLaneTests.cs | 85 +++++++++++++++++++ Jint/Native/Array/ArrayInstance.cs | 43 ++++++++++ .../Expressions/JintAssignmentExpression.cs | 10 ++- 4 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 Jint.Tests/Runtime/ArrayAppendLaneTests.cs diff --git a/Jint.Benchmark/ElementAccessBenchmark.cs b/Jint.Benchmark/ElementAccessBenchmark.cs index 43f60aa13..c6345ad25 100644 --- a/Jint.Benchmark/ElementAccessBenchmark.cs +++ b/Jint.Benchmark/ElementAccessBenchmark.cs @@ -20,6 +20,7 @@ public class ElementAccessBenchmark private Prepared