Overview of Spice parallelism
mainSpice is a Zig library designed for extremely efficient parallelism using heartbeat scheduling. It is optimized for scenarios where the workload per task is small, aiming to minimize the overhead typically associated with fork/join frameworks.
Key characteristics:
- Sub-nanosecond overhead: Converting a function to be parallelism-enabled adds less than a nanosecond of overhead.
- Contention-free: Threads do not compete or spin over the same work. Adding more threads will not slow down the program; extra threads will simply remain idle if no work is available.
- Automatic scaling: Unlike traditional work-stealing libraries that may suffer significant slowdowns on small workloads, Spice detects when the duration is too short for multi-threading and falls back to sequential execution, allowing extra threads to sleep instead of causing contention.