ReviewOS

zig-utils/zig-js

Threads: remove shared allocation and object-model scaling bottlenecks

#478
Open chris opened this 9 days ago ·
9 days ago

Parent: #459 Depends on: #471, #476, #477

Goal

Remove the remaining shared-realm allocation, shape, property, element, and publication bottlenecks so allocation-heavy JavaScript scales monotonically toward available cores.

Current evidence

The latest accepted shared object-churn row reaches 1.48x scaling at eight lanes, while compute/property/call rows reach roughly 4.5–7.7x in the same report. Earlier exact-parent work reduced publication batches 37x and improved an eight-lane candidate 4.83x, so remaining work must start from the current runtime rather than repeat pre-reserve diagnoses.

Scope

  • Profile allocation fast paths, stable IDs, slab/batch reservation, pressure accounting, shape transitions, fixed-shape caches, backing growth, property/element locks, write barriers, safepoint polling, and reserve-tail retention.
  • Introduce per-thread/per-interpreter owned allocation regions, immutable shared shape transitions, sharded metadata, or optimistic/versioned object operations only with explicit tracing and memory-order proofs.
  • Reduce false sharing and cache-line bouncing in hot counters, cell headers, shape tokens, pressure state, and object backing metadata.
  • Coordinate with #471 so mutation does not trigger compile/invalidation storms.
  • Preserve fairness and exact JS program-race semantics; engine state remains race-free.

No-workaround rules

  • Do not switch the benchmark to isolated contexts, enable a GIL, remove allocation/GC work, retain all dead objects, use unbounded reserves, or batch across observable safepoints/effects.
  • Do not retry rejected owned/sharded enumeration or pressure-accounting designs without new attribution.

Acceptance

  • Post-change phase and collapsed-leaf profiles identify the eliminated bottleneck on current exact workload bytes.
  • Shared object churn scales monotonically at 1/2/4/8 lanes with material eight-lane improvement and bounded RSS/reserve tails.
  • Direct and independent object churn, other shared rows, GC generation/compaction, and cold lifecycle do not regress.
  • Full unit, no-GIL corpus, threadfuzz profiles, lifecycle, fault/OOM, and suppression-free TSan pass.
  • Causal exact-parent artifacts and the full comparison matrix are published from clean commits.

Foundation

#49/#97/#426/#427/#445; reserve A/B report; reclaimed cursor e690a866.

9 days ago

Linked #530 tracks the deep-Shape lookup/index design separately from #529 numeric-key lifetime. It explicitly includes immutable/versioned no-GIL transition publication and 1/2/4/8-lane convergence, so a single-thread complexity fix cannot silently introduce shared shape contention.

9 days ago

#530 removed linear deep-Shape lookup and predictable transition hashing in 7666c5f1, with exact-parent evidence in 21a33f13. Four-lane same-shape construction and 256-way fanout convergence are suppression-free TSan clean.

I have intentionally kept #530 open for a real 1/2/4/8 shared transition-throughput result; the functional four-lane witness is not being substituted for #478-style scaling evidence.

9 days ago

Current-main diagnosis split a bounded child into #559. The amplified eight-lane Shape-publication row places GcCellBacking.allocFn at the top collapsed leaf (2,649 samples), with 1,085 scheduler-yield leaves and 511 frees, after Shape writer and named-property contention were ruled down. #559 owns exact size-class attribution and a bounded mutator-sharding design; it explicitly excludes stacks, queues, jobs, Promise/microtask, and Worker lifecycle work.

9 days ago

#597 removed 11,400 redundant cell-slab ownership acquisitions from one representative configuration without changing allocation or execution counters. This is a cold/root-environment correction rather than a shared-object-churn claim, but it removes an adjacent write-barrier metadata bottleneck and is landed in 8e211b2f.

9 days ago

Child #651 is complete and closed. The owned mutable-key snapshot fix plus focused oracle correction passed fresh Debug, ReleaseSafe, and suppression-free TSan no-GIL shard 3/4; all normal unit shards; focused tests; and broad/mid-GC/verify threadfuzz. Closure evidence: /zig-utils/zig-js/issues/651#issuecomment-5360868824

9 days ago

#694 is complete in d5d63780: Environment cache reuse preserves allocation-time ownership metadata and removes the cross-lock TSan race without disabling reuse, marking, or synchronization. Full Debug and TSan units are green.

9 days ago

Shared string-interning follow-up #697 landed in f9ca94d6. Representation-aware interning preserves sharded exact-key convergence and canonical fast paths while safely canonicalizing flat Latin-1 cells; concurrent TSan controls remain green.

9 days ago

Closed child #851 in a1816a9d: the four long-lived Object named-metadata tables now share one lazily installed context and retain the existing property-lock/accessor-gate protocol. Competing first writers passed TSan/no-GIL; no per-map seed header or extra metadata allocation was added, Object remains in its 128-byte slab, and ObjectColdState remains within 256 bytes.

9 days ago

#853 / 0a5d1f70 removes deterministic probe placement from the shared dense-Array hole sidecar without adding hot Object bytes. A four-lane shared-realm delete/probe/fill witness passes Debug and TSan, and the broader 77-test Array TSan inventory is clean.

9 days ago

Completed #860 removes deterministic collision amplification from the no-GIL shared debugger registry: fix(debugger): seed statement location registry (#860). The existing reentrant registry lock remains the sole transaction boundary; the 8-thread dynamic-Function publisher and public debugger matrix pass under TSan.

9 days ago

Related hardening landed: #873 securely seeds the exact-thread-ID ThreadLocal value index, preserves lifecycle/GC semantics, and is implemented by 3cf4429e.

Sign in to comment on this issue.