ReviewOS

zig-utils/zig-js

Runtime: return static cells for typeof result strings

#602
Closed chris opened this 10 days ago ·
10 days ago

Parents: #473, #479 Related: #465, #493

Finding

The post-#601 exact-main cold profile still records managed string construction in ordinary evaluation. Interpreter.applyUnary(.typeof) currently calls Value.strAlloc(self.arena, v.typeOf()) for every resolved operand, although ECMA-262 typeof can return only the fixed strings undefined, object, boolean, number, string, symbol, bigint, or function. Availability probes in context/workload configuration repeatedly allocate, classify, copy, register, trace, and finalize cells whose bytes are compile-time constants. The unresolved-identifier branch already returns the correct static undefined cell, so resolved operands take an unnecessarily different ownership path.

Scope

  • Add one exact Value-returning typeof classifier shared by tree-walker, VM, and native runtime-operation execution through applyUnary.
  • Return compile-time static StringCells for all eight result spellings; retain the byte-slice typeOf() API for embedding/introspection consumers.
  • Preserve HTMLDDA, callable object, Symbol wrapper/primitive, BigInt wrapper/primitive, and ordinary object ordering exactly.
  • Add exact static-cell identity/managed-state tests across every result category and forced tree-walker/required-bytecode execution.

No-workaround rules

  • No cached mutable result objects, realm pool, skipped operand evaluation, altered unresolved-identifier handling, or benchmark-specific recognition.
  • Static cells remain immutable/unmanaged and must continue to compare by exact bytes against runtime strings.

Acceptance

  • Exact-parent attribution proves fewer managed string cells/bytes/finalizers for repeated resolved typeof, with identical result/checksum and no moved allocation.
  • Exact-parent cold and dedicated typeof timing show a material or consistently causal gain.
  • Tree-walker, required bytecode, optimizer runtime fallback, GC, moving-GC, C API, TSan, full units, and affected test262 remain exact.
10 days ago

Implemented and pushed to main in e9d641d3 (perf(runtime): return static typeof strings (#602)).

The shared unary-operator boundary now returns immutable static cells for all eight ECMA-262 typeof strings. This covers tree-walker and bytecode execution while preserving HTMLDDA, boxed Symbol/BigInt, callable-object, and unresolved-identifier behavior.

Measured evidence:

  • Exact 4,480-operation invocation: cumulative managed cells 83,776 -> 74,815 (-8,961 including warmup), GC cell bytes 10,803,840 -> 10,230,336 (-573,504), and backing allocations 159,765 -> 150,802 (-8,963), with identical execution counters and checksum.
  • 41 paired 100-job samples: median 296.245834 ms -> 292.398333 ms (-1.299%); candidate won 41/41 pairs.
  • General cold controls were mixed within -0.169% to +0.538%, so this does not claim a broad throughput improvement.
  • Exact test262 test/language/expressions/typeof: 16/16 pass before and after.
  • Full unit gate: 1,718 passed, 1 skipped, 0 failed, 0 leaked.
  • Focused normal and TSan static-cell identity tests pass.

Sign in to comment on this issue.