Repository navigation
Start-up sets up per-thread allocator rows, the fork list and the wake pipe when first needed - #46
Merged
Merged
Conversation
… wake pipe with the first IO helper A run set the allocator counts of all 128 lanes (8 pages of 128 KB, though only the pool's threads use a row), mapped the main thread's 4 GB fork list at start-up when it had more than one thread (its first use is in the pool, which opens only when a fork is dealt), and opened the event loop's wake pipe, which only IO helper threads write. Now each thread sets its own allocator row when it starts, the main thread maps its fork list when the pool opens, and the pipe opens with the first helper thread; io_wait leaves the pipe out of its select until then. Nothing on a hot path changes. Empty program (one print), M4, hyperfine 500 runs x 2 orders, median: 1.036 to 1.025 ms at 10 threads, 1.032 to 1.020 ms at 1; 12.17M to 11.94M instructions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Merged into integration at 4561e97 (
opt/lazy-startup0efeead, after merging integration babd999; lane statuses equal to integration's; 242 of 244 benchmark programs print expected at 1 thread and the 98 parallel ports at 10, the same two as integration exceed the memory caps: kostya/json at 4 GB, perceus/deriv's emit at 5 GB).Stacks on
opt/integration(418a706).comp.ts+78 ttok (101,434 to 101,512). Runtime only: every program's C changes, in start-up code.What it does
A Bend binary starts about 0.18 ms after a C or Koru one (OPTIMIZATIONS.md §44). This makes three pieces of start-up happen when they are first needed:
corpus_setupset the counts of all 128 lanes' allocator rows (128 KB ofALC, 8 pages touched). Only the pool's threads use a row: each thread now sets its own when it starts (alc_open), the main thread incorpus_setup.io_loopmapped the main thread's 4 GB fork list at start-up. Its first use is in the pool, which opens only when a fork is dealt;pool_opennow maps it.io_work), andio_waitleaves it out of itsselectuntil then.Nothing on a hot path changes (one
io_size != 0test perio_wait).Where the 0.18 ms goes, and what is left
Measured on the empty program (one
IO.print), M4:main)main; ~2 µsmmaped region with touched pages (heap 8 GB, stack 2 GB)mainand printing through the IO loopInstructions: 12.20M to 11.93M on the empty program (C: 10.14M).
Results
hyperfine,
-N, 500 runs (200 for the kernels), both orders, median (ms):On the previous integration base the same runs gave 10-15 µs on the empty program and 10-60 µs on the kernels. This closes roughly a tenth of the 0.18 ms gap; the rest is below.
Instructions on all 244 bend-benchmarks programs (one run each, 98 parallel ports also checked at 10 threads, all print their expected output): 243 measured (kostya/json was killed by the 4 GB cap in this round; on the previous base it measured 5,549M to 5,548M). Instructions change by -0.23M at the median (quartiles -0.47M and -0.01M; -0.009% median relative); the four largest relative increases in the single runs (parallel-ml dedup-entangled +1.4%, linefit-opt +1.4%, linearrec +1.1%) are -0.3%, -0.1% and -0.3% over 5 runs each.
Loss over 5%, placement: osprey
pascalruns +12% cycles at equal instructions (379.9M to 425.4M, median of 5; board 95.1 to 106.9 ms) andtak-10% the other way (board 31.0 to 27.9 ms). Nothing in their loops changes; the runtime's new text moves their code. Over 16 code positionspascalis 0.885x to 1.114x of integration (median 1.039x), so the +12% is one bad position, not a cost of the change.Checks
-DBEND_POISON, live words at 1 and 8 threads, all 1,123 tests since every C changes): all 1,001 that build give the same output, exit code and live words as integration at 1 and 8 threads (8 tests leave words on both: 5 network/heap IO tests and 3 array tests).--gpu onand--gpu off --threads 10; GPU wall 0.98x to 1.02x of integration, CPU 10 threads 0.95x to 1.04x.io_waitselecting on fd 0 before the pipe exists.Not done
"Print main's result directly when no IO loop is running": measured at 5-7 µs for the whole of main's evaluation and print, most of it work C does too; not worth a second print path.
🤖 Generated with Claude Code