Skip to content

perf(vm): step uncaptured number locals in place for i++; - #106

Merged
rekram1-node merged 1 commit into
devfrom
inc-local
Nov 27, 2026
Merged

rekram1-node merged 1 commit into
devfrom
inc-local

Conversation

@rekram1-node

Copy link
Copy Markdown
Member

A i++; or i--; statement (including a for update clause) on an uncaptured, mutable local now compiles to a new INC_LOCAL op in front of the usual GET_LOCAL / INC / PUT_LOCAL. If the local holds a number it steps by one in place and skips those three words. Anything else (BigInt, string, undefined, an object with valueOf, a TDZ hole) runs them as before, so coercion, errors and their locations stay the same. const, captured locals, globals, upvalues, uses of the value (x = i++) and forceExtra builds don't get the op.

Measured on a loaded machine (load average ~10), so numbers are noisy:

before after
for (let i = 0; i < 1e6; i++) s += i, fresh process, best of 9 46.4 ms 39.8 ms (-14%)
same, median of 9 55.6 ms 47.2 ms (-15%)
script/bench.ts numeric loop, best of 21, six alternating runs 6.6–7.4 ms 5.8–6.1 ms (~-12%)

The rest of script/bench.ts was within noise.

Bumps COMPILER_VERSION 5 → 6 and regenerates src/prelude/bytecode.json, so the build id changes and snapshots from older builds are refused. The Rust port has its own compiler and is unaffected.

Tests: semantics and which locals get the op in test/vm.test.ts, the verifier and disassembler know the op, and a new test/snapshot.test.ts program round-trips loops that step numbers, BigInts, strings and objects.

@rekram1-node
rekram1-node merged commit 4ae221e into dev Nov 27, 2026
1 check passed
@rekram1-node
rekram1-node deleted the inc-local branch November 27, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant