ReviewOS

zig-utils/zig-js

Environments: elide binding read locks for private activations

#533
Closed chris opened this 8 days ago ·
8 days ago

Motivation

The shared-realm transition publication benchmark in #531 attributes a material part of per-edge synchronization to declarative Environment reads. Fresh tree-walker function activations are owned by one running mutator until a closure captures them, while the concurrent marker only reads their tables. Taking binding_lock for every identifier read therefore adds atomic traffic without protecting against a mutator writer.

Split from #532 so object descriptor synchronization and Environment ownership remain separately reviewable. Parent performance work: #531. Related shared-realm synchronization work: #478, #480.

Requirements

  • Establish an explicit private-activation invariant for fresh tree-walker call environments and nested declarative scopes.
  • Revoke private status before any closure can publish the environment or an ancestor to another mutator.
  • Keep all binding writes synchronized with concurrent marking; only owner-mutator reads may elide the lock.
  • Root, module, captured, VM, suspended, and otherwise shared environments remain on the locked path unless independently proven private.
  • Preserve lexical lookup, aliases, TDZ, const/function-name metadata, direct eval, with, catch, per-iteration bindings, and closure semantics.
  • Do not weaken GC relocation, concurrent marking, or no-GIL publication ordering.

Acceptance

  • Focused tests prove zero Environment lock acquisitions for private reads and immediate locked fallback after capture.
  • Shared closure and concurrent-GC tests pass under no-GIL and TSan.
  • Full unit suite and relevant test262 scopes have zero regressions.
  • Contention attribution records the before/after Environment lock counts under the #531 workload.
  • Any public performance claim follows the checked-in benchmark-evidence workflow; counter reductions alone are diagnostic, not completion evidence.
8 days ago

Implemented and pushed as perf(environment): elide private activation read locks (#533). Exact evidence: nested private/capture unit proof passed; shared-closure and concurrent-marker tests were TSan-clean; threadfuzz ran 400 deterministic programs with 0 failures; full units were 1,587 passed / 1 skipped / 0 failed / 0 leaked. Exact ReleaseFast test262 test/language remained 23,648 pass / 0 fail (0 flips). Diagnostic attribution retained checksums 5,009,000 and 18,026,000 while invocation Environment locks fell 376,876 -> 36,299 at 4 lanes and 753,608 -> 72,531 at 8 lanes. This is a counter result, not a public throughput claim.

Sign in to comment on this issue.