镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Threads: profile and reduce no-GIL contention #15

Closed

Description

@chrisbbreuer

Parent: #1

Goal

Improve true-parallel shared-realm scaling using measured contention evidence while preserving the .gil = true fallback.

Current baseline

zig build threads-profile compares no-GIL and serialized execution across independent compute, mixed GC-cell allocation, shared properties/arrays, Atomics, locks, conditions, async grants, waits, joins, Promise microtasks, global binding churn, and Worker lifecycle/message paths. Queue front shifts and avoidable lock-held allocator growth have been removed from the main hot queues; GC cell fast paths are locked per size class.

The profiler supports exact focused rows with -Dthreads-profile-case=<name>, broad-or-focused worker-row caps with -Dthreads-profile-max-workers=N, and symbolized safety diagnosis with -Dthreads-profile-debug=true. Shared-realm rows now attribute logical contention, native wait/park time, lock versus async grants, Condition.asyncWait versus property waitAsync, condition waiter-queue growth/compaction (cqgrow/cqcomp), task-pump delivery, Worker channel operations, hidden-class shape transition pressure (shape/newsh/syld), LockedArena pressure (aacq/acnt/aspn), Environment binding-lock pressure (eacq/ecnt/espn), Object backing/property/element lock traffic (ob*/op*/oe*), and Promise/microtask queue behavior.

Promise-focused rows now split enqueue/pop/run counts, reaction versus thenable jobs, queue-lock and Promise-state lock traffic, Promise/new-capability allocation shape, and reaction-list / microtask-queue / drain-batch growth. Worker sections can be focused independently with worker messages and worker teardown filters. The global binding churn row exercises shared global lexical binding reads/writes separately from shared-object property traffic.

Recent local evidence shows repeated mutation in shared object props does not perform shape-transition work after warmup, while mixed GC cell allocation performs high cached shape-transition volume with no new child shapes and no-GIL transition-lock yields that grow with thread count. The condition queue now compacts consumed FIFO prefixes before growth and exposes that churn in the profile table. Representative guidance still documents when .gil = true remains preferable: coordination-heavy task/async-condition handoff can be faster serialized, while independent compute remains the no-GIL-friendly shape. These are local workload-shape examples, not portable thresholds.

Completed milestones

  • Add repeatable exact-scenario 1/2/4/8-thread profiling on representative hosts.
  • Add a Debug safety-check mode without changing normal ReleaseFast timing mode.
  • Attribute logical contention, park/wait time, async registrations/settlements, and task delivery by source.
  • Fix and regression-test the GC-poisoned Promise uncovered by the focused async-condition profile.
  • Preserve a complete broad-profile run across shared-realm and Worker scenarios.
  • Add direct Environment/global-binding lock attribution and a focused global binding churn row.
  • Add direct Object backing/property/element lock attribution to shared-realm profile rows.
  • Add Worker channel/message/teardown attribution.
  • Add Promise/microtask attribution, queue-local locking, queue-lock contention counters, and Promise allocation/growth-shape counters.
  • Add condition waiter-queue compaction plus cqgrow / cqcomp attribution.
  • Document workloads where .gil = true remains preferable, with representative rather than universal numbers.

Remaining work

  • Attribute any remaining property/element, promise, waiter, Worker/agent, GC, allocator/context, and task-delivery contention that still hides behind aggregate counters.
  • Optimize only bottlenecks demonstrated by profiles, beginning with async-condition/task delivery, high-thread property wait/notify, Promise microtask overhead, and shape-transition lock pressure if repeated measurements keep showing them.
  • Add regression counters or focused benchmarks for every changed hot path.
  • Record baselines on additional host/OS/core-count shapes.

Acceptance criteria

  • Changes preserve no-GIL TSan and semantic gates.
  • Each optimization includes a focused invariant test and profile evidence.
  • Shared-state lock ordering remains documented in docs/threads/bindings.md.
  • Safety-check and timing modes agree on behavior; only ReleaseFast numbers are used for performance claims.

Activity

  1. chrisbbreuer commented on Jul 10, 2026

    @chrisbbreuer
    MemberAuthor

    Profiling follow-up observed while completing #14:

    A local zig build threads-profile run completed the independent compute, mixed GC allocation, shared property/array, typed-array Atomics, property wait/notify, and property waitAsync rows, then terminated with SIGSEGV during the Condition.asyncWait matrix after printing the 1-thread and 2-thread rows.

    This was outside the new mid-script-GC telemetry path and was not attributed or fixed by 3b17a78. The collector profile was therefore split into the independent zig build midgc-profile command. Reproduce/minimize this broad-profile crash before using the full contention matrix as a stable baseline; treat it as #15 evidence, not as a #14 regression claim.

  2. chrisbbreuer commented on Jul 10, 2026

    @chrisbbreuer
    MemberAuthor

    Landed b9dd15d fix(gc): remember native synchronization edges on main.

    Reproduction and root cause

    The previously reported threads-profile SIGSEGV was reproduced with:

    zig build threads-profile -Dthreads-profile-case='condition asyncWait'

    Debug mode produced two decisive stacks:

    • runHoldJob -> promise.resolve dereferenced a GC-poisoned outer Promise.
    • With old-space full collection suppressed, createAsyncCondReacquireJob -> barrierHoldJob found that the async condition waiter's Promise had already been reclaimed.

    This isolated the failure to minor collection: an old Condition wrapper stored a young Promise only in its native queue without an owner-aware generational barrier.

    Fix

    • Lock, Condition, and ThreadLocal native records now retain their GC wrapper as barrier owner.
    • Queued lock jobs remember outer promises/callbacks through the Lock owner.
    • Async condition queues remember both the Promise and condition-to-lock wrapper edge.
    • ThreadLocal native-map stores use the ThreadLocal wrapper as owner.
    • Native tracing keeps lock wrappers live while jobs, waiters, or release functions still depend on their side records.
    • Added parallel_js nursery remembers native synchronization side-record edges: tenure wrappers, store young values only in native records, force minor GC, then require condition reacquire and ThreadLocal identity to survive.

    Profiler tooling and evidence

    • -Dthreads-profile-case='<exact name>' runs one 1/2/4/8-thread scenario.
    • -Dthreads-profile-debug=true provides symbolized safety checks; ReleaseFast remains the timing mode.
    • One Debug and three consecutive ReleaseFast focused condition asyncWait matrices passed after the fix.
    • A complete unfiltered zig build threads-profile then passed every shared-realm and Worker row.
    • The profile still shows poor no-GIL scaling for coordination-heavy async-condition/task-delivery workloads; that is the next optimization target, not a resolved performance claim.

    Verification

    • deterministic nursery regression in normal and TSan builds
    • zig build test
    • zig build threads-test — 227/227
    • zig build test -Dtsan=true -Dtest-filter=parallel_js
    • zig build threadfuzz -Dfuzz-iters=20 — 0 failures
    • zig build threadfuzz -Dfuzz-midgc=true -Dfuzz-iters=2 — 90 programs, 0 failures
    • zig build threadfuzz -Dfuzz-verify=true -Dfuzz-iters=300 — 0 failures
    • complete and focused threads-profile runs
    • bun run docs:build
    • git diff --check
  3. chrisbbreuer commented on Jul 10, 2026

    @chrisbbreuer
    MemberAuthor

    Landed 5f06ea4 (docs(threads): document gil fallback guidance (#15)).

    Focused profile evidence from the 2026-07-10 local 11-core run:

    • zig build threads-profile -Dthreads-profile-case='condition asyncWait'
      • 2 threads: no-GIL 15,423,417 ns, .gil = true 1,277,125 ns (vs gil 0.08x)
      • 8 threads: no-GIL 128,598,583 ns, .gil = true 5,951,666 ns (vs gil 0.05x)
      • Interpretation: coordination-heavy task delivery / async-condition reacquire can be better serialized today.
    • zig build threads-profile -Dthreads-profile-case='independent compute'
      • 2 threads: no-GIL 124,460,417 ns, .gil = true 319,059,917 ns (vs gil 2.56x)
      • 4 threads: no-GIL 105,714,375 ns, .gil = true 890,543,916 ns (vs gil 8.42x)
      • 8 threads: no-GIL 141,690,875 ns, .gil = true 2,356,258,375 ns (vs gil 16.63x)
      • Interpretation: independent compute remains the no-GIL-friendly workload shape.

    Docs now say to treat those as representative local examples, not portable thresholds: rerun the exact focused row on the deployment host and prefer .gil = true when vs gil remains below 1.0x and task-delivery counters dominate.

    Validation:

    • focused profile rows above
    • bun run docs:build
    • git diff --check
  4. chrisbbreuer commented on Jul 10, 2026

    @chrisbbreuer
    MemberAuthor

    Landed 326e02f (bench(threads): split lock contention counters (#15)).

    This is an attribution-only profiler improvement:

    • threads-profile now prints lcnt for direct contended Lock.hold attempts and aq for queued Lock.asyncHold grants, split out from the existing aggregate events column.
    • Runtime counters already existed; this exposes them in the profile table for both no-GIL and .gil = true rows.
    • Updated docs/threads/testing.md, docs/threads/production-readiness.md, and docs/threads/limits.md so the profile column guide matches the output.

    Validation:

    • zig fmt bench/threads.zig
    • zig build threads-profile -Dthreads-profile-case='lock contention'
      • confirmed ng lcnt / gil lcnt populate for contended sync lock rows and aq remains 0 there, as expected.
    • bun run docs:build
    • git diff --check

    This moves the first remaining #15 item forward by making existing lock-vs-async-grant attribution visible without changing runtime semantics.

  5. chrisbbreuer commented on Jul 10, 2026

    @chrisbbreuer
    MemberAuthor

    Advanced the async-waiter attribution part of #15 in 89ca516 (bench(threads): split async waiter counters).

    threads-profile now keeps the existing aggregate async/done columns but also prints:

    • caw / cad: Condition.asyncWait registrations / completed reacquires
    • paw / pad: property Atomics.waitAsync registrations / settled tickets

    That makes the existing internal counters visible in the table instead of hiding condition regrant pressure and property timeout-settlement pressure behind a combined async total.

    Focused validation, batched:

    • zig build threads-profile -Dthreads-profile-case='condition asyncWait'
    • zig build threads-profile -Dthreads-profile-case='property waitAsync timeout'
    • bun run docs:build
    • git diff --check

    Evidence from the focused rows:

    • condition asyncWait fills caw/cad and leaves paw/pad at zero (for example, 8-thread no-GIL: caw=1050, cad=1050, paw=0, pad=0).
    • property waitAsync timeout fills paw/pad and leaves caw/cad at zero (for example, 8-thread no-GIL: paw=720, pad=720, caw=0, cad=0).

    This does not claim an optimization yet; it makes the next async-condition/task-delivery and property-waitAsync changes measurable by source.

  6. chrisbbreuer commented on Jul 10, 2026

    @chrisbbreuer
    MemberAuthor

    Advanced the Worker/agent attribution part of #15 in 6c9dfef (bench(threads): expose worker channel counters).

    What changed:

    • Extended the internal opt-in jsthread.ContentionStats profiler counters with Worker channel push, pop, empty-pop, and close counts.
    • Instrumented Worker inbox/outbox channel operations without changing normal Worker semantics.
    • threads-profile Worker message rows now print push, pop, and empty receive null counts alongside timing.
    • Worker teardown rows now print self ops, host ops, and term ops totals, where ops are channel push + pop + empty-pop + close events for that teardown mode.
    • Added exact threads-profile filters for worker messages and worker teardown, so Worker attribution can be checked without running the full shared-realm matrix.
    • Updated the thread docs column guide.

    Validation, batched:

    • zig build test -Dtest-filter="jsthread contention stats reset and snapshot"
    • zig build threads-profile -Dthreads-profile-case="worker messages"
    • zig build threads-profile -Dthreads-profile-case="worker teardown"
    • bun run docs:build
    • git diff --check

    Focused evidence from the local worker messages run:

    • script rows: push/pop exactly matched 2 * workers * 160 round-trip channel operations.
    • empty receive rows: null exactly matched workers * 3000 polls.

    This is still attribution, not an optimization claim. It makes Worker queue/message/teardown pressure visible before changing those hot paths.

  7. chrisbbreuer commented on Jul 10, 2026

    @chrisbbreuer
    MemberAuthor

    Advanced the property/object attribution part of #15 in 644632e (bench(threads): expose shape transition counters).

    What changed:

    • Added opt-in shape transition counters: total transition requests, cache hits, cache misses/new child shapes, and transition-lock yields.
    • Exposed the shape module through js.shape so local profiling tools can snapshot those counters without adding import cycles between shape.zig, promise.zig, and jsthread.zig.
    • threads-profile shared-realm rows now print shape, newsh, and syld for both no-GIL and .gil = true rows.
    • Updated the thread docs column guide.

    Validation, batched:

    • zig build test -Dtest-filter="shape transition stats reset and snapshot"
    • zig build threads-profile -Dthreads-profile-case="shared object props"
    • zig build threads-profile -Dthreads-profile-case="mixed GC cell allocation"
    • bun run docs:build
    • git diff --check

    Focused evidence:

    • shared object props showed shape=0/newsh=0/syld=0 after warmup, so repeated mutation of existing properties is not hidden-class churn.
    • mixed GC cell allocation showed cached shape transition volume (shape=90,000 * thread-count), newsh=0 after warmup, and no-GIL transition-lock yields growing with thread count (for example, 8-thread no-GIL syld=5488 in this local run).

    This is attribution only. It identifies shape-transition lock pressure as measurable in allocation-heavy rows before we decide whether optimizing that path is worth the complexity.

  8. chrisbbreuer commented on Jul 10, 2026

    @chrisbbreuer
    MemberAuthor

    Promise/microtask attribution slice landed on main as 5631d8d (profile(threads): attribute promise microtasks).

    What changed:

    • added src/promise_profile.zig with atomic counters for microtask enqueue/pop/run plus reaction-vs-thenable job split;
    • instrumented promise.zig enqueue/pop/run paths while keeping counters disabled unless profiling explicitly enables them;
    • added a focused zig build threads-profile -Dthreads-profile-case='promise microtasks' filter instead of widening the default table;
    • documented the new profile hook in README/P7 notes.

    Focused local validation passed: zig build threads-profile -Dthreads-profile-case='promise microtasks'. The run produced exact expected counts (for 8 threads: 36,864 enqueue/pop/run, split 24,576 reaction jobs and 12,288 thenable jobs). It also exposed a concrete optimization lead: no-GIL Promise microtasks are much slower than .gil = true despite zero existing contention events, so the next #15 step should profile/reduce the microtask queue / promise job path itself rather than guessing at unrelated locks.

    Fresh CI for this push is pending: https://github.com/zig-utils/zig-js/actions/runs/29114200905.

  9. chrisbbreuer commented on Jul 10, 2026

    @chrisbbreuer
    MemberAuthor

    Promise/microtask contention reduction landed on main as caad91e (perf(threads): use per-queue microtask locks).

    The focused promise microtasks profile showed the no-GIL path doing exact expected job counts but paying a large cost with zero existing Thread contention events. One concrete choke point was that every interpreter pointed at a realm-wide microtask lock even though spawned Threads allocate independent microtask queues.

    What changed:

    • MicrotaskQueue now owns its own lock;
    • no-GIL interpreters lock the current target queue instead of a context-wide lock;
    • retiring thread-local queues transfer pending jobs into the realm queue while locking both source and target queues in address order;
    • P7 notes now document the queue-local invariant.

    Focused local validation: zig build threads-profile -Dthreads-profile-case='promise microtasks' passed after the change with the expected enqueue/pop/run counts preserved. This is a partial #15 reduction, not a claim that Promise microtasks are solved; the profile still shows more no-GIL overhead to chase next.

    Fresh CI is queued: https://github.com/zig-utils/zig-js/actions/runs/29114710319.

  10. chrisbbreuer commented on Jul 10, 2026

    @chrisbbreuer
    MemberAuthor

    Follow-up Promise/microtask attribution landed on main as 0c5041d (profile(threads): count microtask queue lock traffic).

    What changed:

    • promise_profile now records microtask queue lock acquisitions and yield-backed lock contention;
    • MicrotaskQueue.acquire increments those counters only while profiling is enabled;
    • the focused promise microtasks profile prints qlock/qyld columns for no-GIL and .gil = true.

    Local validation:

    • zig build test -Dtest-filter="promise profile stats reset and snapshot"
    • zig build threads-profile -Dthreads-profile-case='promise microtasks'

    Local evidence after the per-queue lock change: exact enqueue/pop/run counts stayed stable, no-GIL records queue lock acquisitions but qyld=0 for the focused workload, and .gil = true records zero queue lock traffic. So this profile now separates actual lock contention from unavoidable no-GIL queue-lock traffic; the next Promise optimization should target lock-traffic/critical-section frequency rather than assuming contended queue locks.

    Fresh CI for this push is pending: https://github.com/zig-utils/zig-js/actions/runs/29115153555. The prior caad91e run had already turned the previously failing tsan-threadfuzz-lifecycle leg green before this follow-up push.

  11. chrisbbreuer commented on Jul 10, 2026

    @chrisbbreuer
    MemberAuthor

    Promise/microtask optimization follow-up landed on main as aa697df (perf(threads): batch microtask queue drains).

    Why this was the next logical #15 step: the new qlock/qyld counters showed the focused workload had queue lock traffic but no yield-backed contention after the per-queue lock change. So the bottleneck to reduce was lock frequency / per-job synchronization overhead, not contended waiting.

    What changed:

    • drainMicrotasks now atomically moves the current pending burst out of the target queue under one queue lock, then runs that burst unlocked;
    • jobs enqueued by that burst (or by peers) stay in the queue for the next burst, preserving per-queue FIFO;
    • the active dequeued batch is traced as an interpreter GC root, just like current_microtask, so callbacks/GC cannot collect jobs that have been removed from the queue but not run yet;
    • promise_profile has a bulk pop counter so focused profile counts remain exact.

    Local validation:

    • zig build test -Dtest-filter="promise profile stats reset and snapshot"
    • zig build test -Dtest-filter="memory model: spawned thread drains its FIFO microtasks before completion"
    • zig build threads-profile -Dthreads-profile-case='promise microtasks'

    Focused local evidence: enqueue/pop/run counts remained exact; qlock dropped roughly from ~74k to ~37k at 8 threads with qyld=0, confirming the change reduced queue lock frequency while preserving behavior. Fresh CI is pending: https://github.com/zig-utils/zig-js/actions/runs/29115438190.

  12. chrisbbreuer commented on Jul 10, 2026

    @chrisbbreuer
    MemberAuthor

    Profiler/docs chunk pushed in zig-js@e2dfea1 (profile(threads): compare promise gil gc mode):

    • The focused promise microtasks profile now includes a gil+gc mode/column, so we can separate serialized fallback cost with GC-managed cells from no-GIL queue-lock/scheduling overhead.
    • Docs now describe the queue-local MicrotaskQueue.lock, batch dequeue into interpreter-local active roots, and the updated Promise reaction-list settlement model.
    • Local validation already run before commit:
      • zig build threads-profile -Dthreads-profile-case="promise microtasks"
      • bun run docs:build
      • stale wording scan for old Context.microtask_lock / lock-gate text.
  13. 31 remaining items

  14. chrisbbreuer commented on Jul 12, 2026

    @chrisbbreuer
    MemberAuthor

    CI routing note: the previous current gate was superseded by the follow-up #36 async-generator push. The current main-branch gate that includes the condition-queue chunk and later history is now: https://github.com/zig-utils/zig-js/actions/runs/29200819725

  15. chrisbbreuer commented on Jul 12, 2026

    @chrisbbreuer
    MemberAuthor

    CI routing note: the previous current gate was superseded by the follow-up #36 generator-handler push. The current main-branch gate that includes the condition-queue chunk and later history is now: https://github.com/zig-utils/zig-js/actions/runs/29200885804

  16. chrisbbreuer commented on Jul 12, 2026

    @chrisbbreuer
    MemberAuthor

    CI routing note: the previous current gate was superseded by the follow-up mid-GC telemetry push. The current main-branch gate that includes the condition-queue chunk and later history is now: https://github.com/zig-utils/zig-js/actions/runs/29201026809

  17. chrisbbreuer commented on Jul 12, 2026

    @chrisbbreuer
    MemberAuthor

    Pushed a small #15 attribution slice in 03092fb0 (profile(condition): count waiter queue churn).

    What changed:

    • Added internal contention counters for condition waiter-queue backing growth (cqgrow) and consumed-head compaction (cqcomp).
    • Printed those counters in zig build threads-profile beside caw/cad, empty/jobs, and hold/cjob, so notify-heavy / Condition.asyncWait rows can separate allocation pressure from amortized FIFO churn.
    • Tightened the direct condition queue compaction unit witness to assert the new counters: growth happened before the queue filled, compaction increments once, and the compaction append does not require a new growth.
    • Updated thread testing and production-readiness docs with the new columns.

    Focused validation:

    • zig build test -Dtest-filter="condition queue compacts consumed head before growing" --summary all
    • zig build test -Dtest-filter="jsthread contention stats reset and snapshot" --summary all
    • zig build threads-profile -Dthreads-profile-debug=true -Dthreads-profile-case="condition asyncWait multi-lock" -Dthreads-profile-max-workers=1 --summary all
    • bun run docs:build
    • git diff --check

    CI: https://github.com/zig-utils/zig-js/actions/runs/29201263212 is pending for 03092fb0. This does not optimize the queue further by itself; it makes the existing condition queue amortization measurable in the #15 profile table so the next optimization choice can be evidence-based.

  18. chrisbbreuer commented on Jul 12, 2026

    @chrisbbreuer
    MemberAuthor

    Routing note: the CI run linked for 03092fb0 was cancelled by the newer #13 workflow-support push. The #15 condition-profiler code remains on main; use current combined-head CI for 36c0159a: https://github.com/zig-utils/zig-js/actions/runs/29201371564 (queued at the time of this note).

  19. chrisbbreuer commented on Jul 12, 2026

    @chrisbbreuer
    MemberAuthor

    Routing note: the combined-head CI run for 36c0159a was cancelled by the newer #16 nursery-profile push. The #15 condition-profiler counters remain on main; use current combined-head CI for b79f9774: https://github.com/zig-utils/zig-js/actions/runs/29201561685 (queued at the time of this note).

  20. chrisbbreuer commented on Jul 12, 2026

    @chrisbbreuer
    MemberAuthor

    Routing note: current combined-head CI moved with the #12 memory-model docs push. The #15 condition-profiler counters remain on main; use current combined-head CI for d0092f5e: https://github.com/zig-utils/zig-js/actions/runs/29201642565 (queued at the time of this note).

  21. chrisbbreuer commented on Jul 12, 2026

    @chrisbbreuer
    MemberAuthor

    Green gate note for d0092f5e: https://github.com/zig-utils/zig-js/actions/runs/29201642565

    The condition waiter-queue compaction/counter attribution and broader profiling updates are covered by the successful combined gate. This keeps the next optimization work tied to measured profile evidence rather than speculative tuning.

  22. chrisbbreuer commented on Jul 12, 2026

    @chrisbbreuer
    MemberAuthor

    Implemented another small #15 contention slice in b09fd1e (shape: bypass transition wait on published cache).

    What changed:

    • Shape.transition now re-checks the append-only transition cache while waiting for transition_lock.
    • If another thread wins the race and publishes the same child shape, waiters return the cached transition immediately instead of continuing through the lock just to discover the existing child in the hashmap.
    • Added a focused regression test that holds the transition lock and verifies the wait path observes a published cache entry.

    Validation run locally:

    • /Users/chris/.local/bin/zig build test -Dtest-filter="shape transition" --summary all → 5/5 passed.
    • /Users/chris/.local/bin/zig build threads-profile -Dthreads-profile-debug=true -Dthreads-profile-case="mixed GC cell allocation" -Dthreads-profile-max-workers=2 --summary all → succeeded; capped row reported ng syld/gil syld as 0 for 1- and 2-worker rows.
    • git diff --check → clean.

    CI is queued on main at https://github.com/zig-utils/zig-js/actions/runs/29212985607; I will watch it before taking the next issue slice.

  23. chrisbbreuer commented on Jul 13, 2026

    @chrisbbreuer
    MemberAuthor

    CI follow-up for b09fd1e: the main CI run is now green after rerunning the only failed job.

    Final status: https://github.com/zig-utils/zig-js/actions/runs/29212985607 → 31 successful jobs, 1 skipped, 0 failed.

    Note: the initial run had a transient threadfuzz-midgc failure in the known midgc termination-reaction did not finish a parallel collection area. Local targeted reproduction passed (THREADFUZZ_SEED_TIMEOUT_MS=300000 zig build threadfuzz -Dfuzz-midgc=true -Dfuzz-iters=1 -Dfuzz-seed=8 --summary all → 45 programs, 0 failures), and the GitHub failed-job rerun passed.

  24. chrisbbreuer commented on Jul 13, 2026

    @chrisbbreuer
    MemberAuthor

    Landed a small #15 optimization slice in 9d8d54ef (perf(object): combine literal property locks).

    What changed:

    • Added Object.defineLiteralDataOwn, which performs the object-literal accessor delete/probe and data-property write under one property_lock acquisition.
    • Routed both tree-walker and VM object-literal data initialization through that helper.
    • Added a focused counter regression: ordinary data-only object literals now add one property-lock acquisition per data property over the empty-literal baseline, rather than the old delete-accessor probe + set-own pair.

    Why this slice:

    • After b09fd1e5, the focused mixed GC cell allocation profile showed shape transition-lock yields stayed at 0 through 4 workers, so the next visible pressure was object property locking from literal-heavy allocation.
    • This keeps the lock load-bearing for concurrent GC tracing; it only avoids dropping/re-taking it between two operations that already need the same lock.

    Focused validation:

    • zig build test -Dtest-filter="object literal data properties take one property lock each" --summary all
    • zig build test -Dtest-filter="object literal" --summary all
    • zig build test -Dtest-filter="interpreter object" --summary all
    • zig build threads-profile -Dthreads-profile-debug=true -Dthreads-profile-case="mixed GC cell allocation" -Dthreads-profile-max-workers=4 --summary all
    • git diff --check

    Profile evidence from the local focused row:

    • Before this slice, mixed GC cell allocation reported ng opacq of 240120 / 480186 / 960318 for 1/2/4 workers.
    • After this slice, the same focused row reported ng opacq of 210120 / 420186 / 840318 for 1/2/4 workers.
    • That is exactly 30,000 fewer property-lock acquisitions per worker for this workload, while syld remained 0.

    Fresh CI is queued on main for the new head; I’ll track it separately from the prior e132c6fe run.

  25. chrisbbreuer commented on Jul 13, 2026

    @chrisbbreuer
    MemberAuthor

    Landed another measured #15 allocator-contention slice in 7e0afd2e (perf(arena): skip local chunk lock probes).

    What changed:

    • LockedArena now records the current thread-local bump chunk start/end.
    • resize, remap, and free first reject/no-op memory from the current local chunk without taking the global arena lock.
    • Older local chunks and non-local arena allocations still use the existing locked local_chunks ownership scan, so this only removes lock traffic for the current thread's current bump chunk.
    • Added a focused counter test proving current-local resize / remap / free do not increment arena_lock_* counters.

    Why:

    • The focused promise microtasks profile had qyld=0 and pyld=0, so queue and Promise-state locks were not the bottleneck. The visible contention was LockedArena (aacq/acnt/aspn), mostly from allocator API calls around thread-local bump allocations.

    Focused validation:

    • zig build test -Dtest-filter="LockedArena" --summary all
    • zig build threads-profile -Dthreads-profile-debug=true -Dthreads-profile-case="promise microtasks" -Dthreads-profile-max-workers=4 --summary all
    • git diff --check

    Profile evidence from the local focused row:

    • Before: 4-worker no-GIL promise microtasks reported ng aacq=19014, ng acnt=2466, ng aspn=465644.
    • After: 4-worker no-GIL promise microtasks reported ng aacq=504, ng acnt=0, ng aspn=0.
    • 1-worker ng aacq similarly dropped from 4722 to 90; 2-worker from 9504 to 246.

    Timing remains noisy, so the claim here is deliberately the contention-counter reduction, not a portable wall-clock speedup.

  26. chrisbbreuer commented on Jul 13, 2026

    @chrisbbreuer
    MemberAuthor

    CI routing note: the 7e0afd2e run for the recent no-GIL contention chunks was clean at 24 success / 1 skipped / 0 failures before being superseded by the follow-up mid-GC generation hardening push.

    The current combined-head gate that includes the arena-lock and object-literal contention reductions is now: https://github.com/zig-utils/zig-js/actions/runs/29216356732

  27. chrisbbreuer commented on Jul 13, 2026

    @chrisbbreuer
    MemberAuthor

    Closing this measured-contention tracker as completed.\n\nThe delivered profiling surface covers exact 1/2/4/8-thread rows, Debug safety mode, shared properties/elements/environments, shapes, GC/allocators, Lock/Condition and property waiters, tasks, Promise/microtask queues, Worker messaging/teardown, park/wait time, and queue growth/compaction. The issue history records focused evidence and invariant tests for each optimization, including queue-local microtask locks, published shape-transition cache bypass, combined object-literal property locking, current-local LockedArena lock elision, condition FIFO compaction, and the related allocation/queue attribution.\n\nThe supported decision is also documented: independent compute is the no-GIL-friendly shape; coordination-heavy async-condition/task-delivery workloads may remain faster with .gil = true, and embedders should measure the exact row on their deployment host rather than rely on a universal threshold.\n\nAcceptance is met: each changed hot path has focused counters/tests and profile evidence, lock ordering is documented, Debug and ReleaseFast modes agree semantically, and the full no-GIL/TSan/semantic matrix is green: https://github.com/zig-utils/zig-js/actions/runs/29232877388.\n\nAdditional hosts and future contention discovered as the engine evolves are ongoing benchmarking, not unfinished scope. A new measured bottleneck should open a narrow issue with before/after counters rather than keeping this umbrella permanently open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions