ReviewOS

zig-utils/zig-js

Perf: hoist exclusive dense-loop access guards out of each replacement

#75
Closed chris opened this 11 days ago ·
11 days ago

Parent: #62 Follows: #74 / cfed7bc

After hoisting immutable shape validation, the fresh object_churn profile attributes 325 top-of-stack samples to Interpreter.checkRestricted and 227 to Object.replaceDenseElement. The structurally quickened path is already disabled for parallel/shared execution and escaped frames, performs no calls or other re-entry, validates a dense hole-free ordinary array at entry, and checks each selected index before mutation. Repeating the thread restriction check and dense presence/lock guards for every replacement is therefore redundant inside one quick chunk.

Scope:

  • expose a non-throwing restriction-access predicate shared with checkRestricted
  • at quick-loop entry, fall back to ordinary bytecode when the current thread cannot access the receiver so the eventual error retains its exact bytecode position
  • add an explicitly exclusive known-present dense replacement helper that retains the GC insertion barrier but omits locks, bounds, and hole probes
  • call it only after the isolated/no-reentry path has validated array shape and the current element index
  • leave shared/no-GIL and all generic element operations unchanged

Acceptance:

  • direct tests cover allowed/unrestricted and rejected foreign restriction ownership
  • exclusive replacement retains the stored object/value and GC barrier path; the VM exact result/step and Proxy/accessor fallbacks remain green
  • profile removes per-iteration checkRestricted and generic replaceDenseElement overhead while retaining header/barrier attribution
  • pinned cfed7bc A/B is repeatably faster with exact checksums
  • run the full unit plus benchmark-harness suite once after the measured win
  • commit references this issue and is pushed as Chris without coauthors
11 days ago

Rejected after implementation and focused validation; nothing from this experiment was committed.

Pinned cfed7bc versus candidate A/B used seven alternating process pairs with three timed samples per process:

  • baseline median of process medians: 266.403875 ms
  • candidate median of process medians: 266.860959 ms
  • elapsed change: -0.17% (neutral/slightly worse)
  • candidate won only 1 of 7 pairs
  • checksum 1030552128 matched in all 42 samples

Although symbol attribution suggested restriction/dense-presence checks were hot, the compiler already made their isolated-path cost effectively negligible. The experiment was fully reverted. The next work should target the barrier and nursery sweep/free costs that remain real function-level work.

Sign in to comment on this issue.