ReviewOS

zig-utils/zig-js

JSON.stringify: elide single-owner snapshot mutexes

#1005
Closed glennmichael123 opened this 9 days ago ·
9 days ago

Problem

The #1002 stable-key path still takes property_lock once to snapshot each simple object key list and again for every live slot read. In the frozen representative JSON invocation, pre-#1004 attribution recorded 3,589,937 property-lock acquisitions (3,570,645 named-snapshot acquisitions) while 1,983,390 of 1,984,837 shape transitions were cache hits. The process is a single-owner, non-concurrent Context, yet its JSON stable-key reads pay the same mutex path required by no-GIL and concurrent-GC realms.

Change boundary

Add an enable-only process gate for published named-property snapshot reads, activated by the existing enableParallelSync boundary before concurrent GC or parallel JS can observe an object. Stable JSON key/slot snapshots may skip property_lock only while that gate is false. Parallel/concurrent contexts retain the exact lock and revalidation path. Do not weaken writers, accessor reader gates, GC barriers, or any generic property lookup.

Completion

Pin unit evidence that the single-owner path records zero named snapshot locks and the enabled path records the expected locks. Preserve live mutation/accessor fallback semantics, JSON Test262 and required VM/tree agreement, OOM/deep/cycle/GC, and no-GIL TSan. Compare current-main attribution counters and seven exact-parent alternating pairs on both frozen JSON rows plus array-heavy and object-only controls with exact checksums. Land only on a measured non-regression.

Parent: #473. Follows #1002 and #1004.

9 days ago

Landed on main as 4b3a14f. Stable JSON key and value snapshots now skip property mutexes only before the enable-only parallel/concurrent publication gate is raised; concurrent GC and no-GIL contexts retain the exact prior lock/revalidation path. Attribution removes exactly 2,772,000 named-snapshot lock acquisitions per frozen invocation (3,589,937 to 817,937 total property locks) with identical shape, allocation, GC-cell and checksum counts. Seven exact-parent pairs: representative_json 0.9885x instructions / 0.9709x CPU, variant confirmation 0.9931x / 0.9584x, shallow-4096 0.9723x / 0.9579x, depth-4096 0.9723x / 0.9773x. Gates: lock-counter unit 1/1, JSON stringify semantic/OOM/deep/GC 14/14, TSan/no-GIL 2/2, JSON Test262 165/165, required VM/tree agreement 165/165.

Sign in to comment on this issue.