Repository navigation
iyi 0.21.0 runs on every core by default, and data races are still compile errors.
A plain g.spawn { } now runs in parallel wherever the compiler can prove it safe. Loops spread across cores with map_parallel and sum_parallel. iyi test --chaos replays any scheduling order from a seed. The runtime under all of this was rebuilt for many cores: channels, mutexes, the worker pool, the clock and the collector. You don't annotate anything and you don't pick threads. If your program compiled before and is safe to parallelise, it now uses your cores.
Every number below was measured on three machines and is labelled with its machine: a shared Linux x86_64 VM with 12 vCPUs, macOS 26.6 on an Apple M2 Pro with 10 cores, and Windows 11 with 12 logical processors. CHANGELOG.md has the method behind each one: runs, best or median, and interleaving.
At a glance
| before 0.21 | 0.21.0 | ||
|---|---|---|---|
| 12 task pairs talking over channels, Linux | 1.49 M msg/s | 57.3 M msg/s | 38× |
| same, Windows | 1.13 M msg/s | 38.2 M msg/s | 34× (Go's twin: 24.5 M) |
| same, M2 Pro | 0.85 M msg/s | 27.5 M msg/s | 32× |
64 plain spawns hashing 31 MiB, Windows |
95 ms (1 worker) | 10 ms (12 workers) | 9.5× |
| same, Linux | 99 ms | 12 ms | 8.3× |
| same, M2 Pro | 158 ms | 20 ms | 7.9× |
--release build of a TLS + HTTP program, Linux |
22.45 s | 7.87 s | 2.9× |
| same, M2 Pro | 22.24 s | 7.94 s | 2.8× |
| peak memory, 12 workers allocating flat out, Linux | 692–856 MB | 158–180 MB | 4–5× less |
| issue #145's web app, peak working set, Windows | 493 MB | 220 MB | 2.2× less |
Parallel by default, safe by proof
- One spawn verb, and it goes parallel when that's safe (SPEC III.4.15, III.4.16).
- A
g.spawn { }whose block touches nothing another thread could race on is placed on the worker pool by itself. - Anything else stays in its spawner's unit exactly as before. Nothing that compiled stops compiling, and no new warnings appear.
- Across the repository's own programs, 125 spawn sites now run in parallel without being edited.
--explain-spawnand an editor inlay hint tell you, for each spawn, which way it went and why.
- A
- Units are a named concept (III.4.18).
- A unit is a set of tasks of which at most one runs at a time.
g.spawn(unit: :new)andg.spawn(unit: :same)say where a task goes. Unit(T)instd/unitholds state that exactly one unit may reach.- Tasks may interleave at a park, the way Swift actors do.
- A unit is a set of tasks of which at most one runs at a time.
- Data parallelism as a library:
std/parallel(III.4.14).each_parallel,map_parallel,sum_parallelandreduce_parallelwork onList,Arrayand ranges, and split the work Rayon-style.- CPU-bound sums, SHA-256 and a string transform ran 6.4–7.4× faster on the M2 Pro's 10 cores and 6.4–7.9× faster on Windows' 12 than one thread did.
- The compiler refuses a block that isn't safe to share, and names the one-thread twin as the way out.
iyi test --chaos[=SEED](III.4.17).- Every scheduling choice is drawn from a seed, so a test that passes only because its tasks happened to run in one order fails, and the same seed fails the same way every time.
- The compiler already rules out memory races; this finds the ordering bugs that are left.
@[SafeReach]is proven, not trusted (III.4.4).- Unsafe code says so:
@[Unsafe("why")](III.13).- A module that touches raw memory carries one mark with a reason, and the compiler refuses unmarked raw memory.
- The safe byte calls
String#byte_at,Bytes.ofandString.new(Array(UInt8))let modules drop the mark. With them, 16 std modules and ten of the repository's benchmark programs need no mark at all. - This is the foundation for the heap-per-unit work planned next.
A runtime rebuilt for many cores
- A lock per channel. Channels used to share the scheduler's one lock. That was the 32–38× in the table above. Twelve producers into one channel went from 1.93 M to 14.4 M values/s on Windows (Go: 12.4 M).
std/mutex: two locked instructions instead of seven, and nothing allocated.- An uncontended update went from 16–18 ns to 11–12 ns on Linux.
- Twelve tasks on one mutex went from 21.6 M to 40.1 M updates/s on Linux and from 21.3 M to 34.8 M on Windows.
- A waiter that starves is handed the lock.
- The pool starts one worker and grows to the work. A program whose one parallel spawn prints a line went from 2.46 ms to 0.68 ms on Linux, and its peak from 82 MB to 17–28 MB.
- The collector has a ceiling. With twelve workers allocating flat out, peak memory fell to 158–180 MB on Linux (from 692–856), 156–162 MB on the M2 Pro (from 408–481) and 154–161 MB on Windows (from 204–265). A size class the program stops using gives its memory back.
- Linux reads its clocks through the vDSO. A read costs 17–18 ns instead of 64–65, with no libc dependency added.
The compiler uses your cores too
--releaseoptimises on every core.- The build is cut into partitions that are compiled in parallel, with ThinLTO-style copies so that inlining still crosses the cut.
- On a TLS + HTTP program: 22.45 s → 7.87 s on Linux, 22.24 s → 7.94 s on the M2 Pro.
- The binaries run within 1.2% of the one-module build.
- Windows keeps one module by default.
IYI_RELEASE_PARTITIONS=0turns the cut on there (30.65 s → 12.14 s).
- Debug builds compile units on threads and parse imports ahead of time. Cold builds are 27% faster on Linux (1.53 s → 1.12 s), 25% on the M2 Pro (1.16 → 0.87) and 14% on Windows (2.85 → 2.45). Peak compiler memory went down too.
A real application: issue #145
The web app from #145, with 11 GET endpoints on 12 workers, measured on Windows against its Go twin:
| 0.20 | 0.21.0 | Go | |
|---|---|---|---|
| requests/s (geometric mean) | 605.3 | 608.5 | 564.7 |
| app CPU per request | 4.56 ms | 4.56 ms | 5.00 ms |
| peak working set | 493 MB | 220 MB | 129 MB |
| p99 latency (geometric mean) | 171.0 ms | 159.7 ms | 102.2 ms |
iyi serves more requests than Go on less CPU per request. Go still leads on tail latency and memory, and both come from collecting one shared heap. That is what the next step targets: a heap per unit, which only works because iyi's compiler already proves which values never leave their unit. Go's type system can't prove that. See PARALLEL_PLAN.md.
Soaked on all three machines
Every CI job passed on the release head. The code under it was also soaked on all three machines; the only change since is #165's one ==. The soak covered:
- web loads of about 30 minutes on each machine, with memory sampled every 30 s. Memory comes back at each collection and levels off, and there are no leaks. On the Linux VM the server ran at a median of about 284 k req/s for
check_version. - 6,000–8,000 chaos seeds per machine.
- 600–1,000
spawn_fuzzseeds per machine, with zero findings. thread_exerciseandconcurrent_markrepeated tens of times.
What you need to change
spawn_parallel,spawn_serial,serial:andparallel:are now compile errors that name the new spelling.iyi fixrewrites them.- A module that handles raw memory needs
@[Unsafe("why")], or the safe byte calls. 0.20.1 refuses the mark, so code that carries one needs 0.21.0. - Libraries need releases that carry their own marks. Releases of iyi-db, iyi-web, iyi-pg and iyi-metric that build on 0.21.0 follow this one.
- The unsafe check adds about 5% to
iyi checkon a small program and 10–26% on a large one. This is measured on all three machines and stated in SPEC III.13.
Also in 0.21.0
- On a Mac, a path typed in another case is the file it names.
- Two pointers compare equal when they hold the same address (#165, thanks @Tuntii).
iyi initwith no module path names the project after its directory (#156).- On Linux, C called from a parallel task or an
IyiThreadruns on a thread that libc made, sopthread_self,strerroranderrnobehave (#158). - CI runs a fast tier on pull requests and the full set everywhere else.
The full list, with every measurement and its method, is in CHANGELOG.md.