$ show judofyr/spice
Spice is a Zig library for low-overhead parallelism using heartbeat scheduling. It provides a fork/join model where workers maintain local work queues and a heartbeat thread periodically signals workers to offload work to others. The design avoids common work-stealing pitfalls: dynamic dispatch is minimized by using static calls for local work, queues are truly local (no atomics for push/pop in common case), and spinning is eliminated by using blocking waits. The library is demonstrated with a binary tree sum benchmark showing sub-nanosecond overhead. While primarily a research project with noted limitations (lack of tests, no array support), the implementation exhibits high craftsmanship in its concurrency primitives and performance optimizations.
The LLM identified 1 files worth highlighting for reuse:
The Job struct implements a branch-free doubly-linked list used as a per-worker queue. It enables lock-free push/pop operations in the common case (no atomic operations) by leveraging the fact that each worker is the sole producer for its queue. State (pending, queued, executing) is encoded in the pointer fields to minimize space. This data structure is a key innovation that reduces synchronization overhead and could be adapted for other scenarios requiring per-thread work queues with occasional stealing.