Repository
lib-parallel
Scoped parallel phases over disjoint output slices for Kinogaki's libraries (crate kinogaki-parallel).
- GitHub
- kinogaki/lib-parallel (private)
- Folder
libs/lib-parallel/- Crates
- 1
- Rust lines
- 558 in src, 311 in tests
Crates
| Crate | What it is | Files | Lines | Test lines |
|---|---|---|---|---|
kinogaki-parallel | Scoped parallel work over disjoint output slices, sized by cost. | 5 | 558 | 311 |
README
lib-parallel
Scoped parallel phases over disjoint output slices for Kinogaki's libraries (crate kinogaki-parallel). Studio's core, its kernels and lib-script share it. It depends on nothing.
Parallel phases run on scoped threads (std::thread::scope) over disjoint output slices. A persistent pool would need unsafe to lend borrowed kernel data, so it is deliberately absent (owner decision, 2026-10-15). Starting a thread costs about 8 µs on Linux and macOS but 60–250 µs on Windows, so each call site's worker count comes from measured costs: the site remembers its time per item, each run measures thread start latency, and W = √(2·work/start) (thread k starts at about k·start and works to the end). The caller works from the start while one helper starts the others; blocks are handed out on demand (four per worker). Results never depend on the worker count: callers write disjoint slices, and workers accumulate into locals and write their slot once (neighboring slots share a cache line). Which error chunks_mut returns when several blocks fail depends on timing; callers that need a deterministic error record one per block and choose the lowest index themselves.
One budget for the process. Every phase's helpers come from one process-wide budget (set_budget, default unlimited): a phase takes what is free when it starts, never waits for more, and runs on its caller alone when none is. A thread's share (with_share) caps its own phases' helpers, and helpers inherit it. set_thread_start runs a hook as every helper starts (an application lowers background threads' priority with it). Kinogaki Photo keeps cores free for its user interface this way while a develop, thumbnails and an export each run kernels.
crates/parallel/examples/phase_overhead.rs measures one phase's overhead.
