Skip to content

perf(runtime): adaptive yield budget for idle pool workers - #44

Draft
nicolas-abril wants to merge 1 commit into
mainfrom
opt/pool-park
Draft

nicolas-abril wants to merge 1 commit into
mainfrom
opt/pool-park

Conversation

@nicolas-abril

@nicolas-abril nicolas-abril commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

On main (6180be5b)

This PR is a port onto main, on main: 1 commit of its own, with no integration history (head 65f9bc6b).

Port notes

Checks

  • Cluster gate (every test, every lane): 1872 / 1872 pass.
  • Locally: no new tsc errors against main, no new comp.ts lines over 80, its tests pass on the C and JS lanes (plus 40 lane runs of existing tests; run/array_slab fails on main too).
  • comp.ts: +161 tokens (ttok -m gpt-3.5-turbo) over main, which is at 65,989 of the 66,000 cap.

Performance was measured on integration when this change merged there (see the original description or the replaced PRs); it has not been re-measured on main.

Original description (written for integration)

Based on opt/integration (3024810); the diff against main includes the integration branch.

What

An idle pool worker waiting for the next turn yielded 128 times (about 300 µs) before it slept on pool_wake. A program whose parallel turns sit between long serial parts therefore paid a core's worth of sched_yield calls per worker per gap: in a 10-thread profile of the tar decoder, yields (swtch_pri) were about 24% of all samples.

Each worker's yield budget now adapts:

  • a wait that ended by sleeping halves it, down to 4;
  • a wait that the yields ended doubles it, up to 128.

Short gaps keep spinning, and long ones stop spinning after a few turns. The main thread's join wait keeps a fixed budget of 128.

Tried and rejected

change result
a fixed 4 yields seam-carve-index +58% wall, seam-carve +39%, ocaml-lu-decomp +33%
a fixed 32 yields seam-carve-index +11%, ocaml-lu-decomp +8%
shorter hunter wait in fk_help (4096 → 128 tries) the main cause of the losses above; left unchanged

Measurements

All 98 parallel ports (parallel-ml/, osprey/*/bend-par/), run on the cluster at 10 threads with 11 interleaved reps each, A and B on the same node. The first (cold) rep is dropped and the median is taken.

  • Wall: geomean −0.9%; programs over 50 ms −0.9%.
  • Cycles: geomean −0.1%. These cycle counts leave out kernel time, so they don't show the saved yields.
  • Over +5% wall: flatten +6.9% and linearrec-opt +5.6%. Rerun alone with 31 reps they come out −0.1% each, so both are noise.
  • Largest gains: fib −17.6%, tak −9.8%, linefit −9.2%.

Tar decoder (local, 10 threads, 7 reps): same wall time, user+sys CPU −6% to −12% across five archives.

Tests: all 1958 tests with expected output, on the cluster lane (run, plus the memory check at 1 and 8 threads). Statuses and live-word counts are identical to integration.

comp.ts: +161 ttok (102,364 → 102,525).

🤖 Generated with Claude Code

… its gaps

A worker waiting for the next pool turn yielded 128 times (some 300us)
before sleeping, so a program whose turns come between long serial parts
paid a core's worth of sched_yield calls per worker per gap. Its budget
now halves after a wait that slept (down to 4) and doubles after one the
yields ended (up to 128): short gaps keep spinning, long ones stop.

A fixed lower count was tried first: 4 lost up to 58% wall on
seam-carve-index, 32 still lost 11% there and 8% on ocaml-lu-decomp.
The hunters' wait (fk_help) is unchanged; shortening it lost more.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 44b5f4b)
nicolas-abril added a commit that referenced this pull request Dec 1, 2026
…33, #34, #36, #39, #44, #61-#68): record their heads

Each is a port onto main of integration's own branch, its content already
here (integration keeps the original commits; the ports add type fixes,
line wraps, moved pieces and #68's book_passes, applied in the previous
commit). Groups: #61 (#9 #11 #15 #32 #41 #42), #62 (#26 #56), #63 (#48 #50
and compile-time), #64 (#19 #20 #45), #67 (#55 #58), #68 (#54); par-defer
(#43) is now part of #34, lazy-startup's parts are in #16 and #34. This
merge records their heads (-s ours: no content change).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant