ZeroAllocJobScheduler 2.0.1

dotnet add package ZeroAllocJobScheduler --version 2.0.1
                    
NuGet\Install-Package ZeroAllocJobScheduler -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZeroAllocJobScheduler" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroAllocJobScheduler" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ZeroAllocJobScheduler" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ZeroAllocJobScheduler --version 2.0.1
                    
#r "nuget: ZeroAllocJobScheduler, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ZeroAllocJobScheduler@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ZeroAllocJobScheduler&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ZeroAllocJobScheduler&version=2.0.1
                    
Install as a Cake Tool

ZeroAllocJobScheduler Maintenance Nuget License C# Build

A high-performance, allocation-free C# job scheduler for game development and data-oriented programming. It runs the parallel work of Arch, the ECS, but fits any game loop.

  • ๐ŸŽ๏ธ FAST > Work stealing, lock-free queues and cache-friendly data. A small job costs a fraction of a microsecond to schedule and finish!
  • โ™ป๏ธ ZERO ALLOC > Scheduling, waiting, dependencies and parallel-for do not create garbage, and tests make sure it stays that way.
  • ๐Ÿ˜ด POLITE > Idle workers sleep, so your game keeps its CPU for rendering, audio and the rest. No spinning cores!
  • ๐Ÿค BARE MINIMUM > Three calls to remember: Schedule, Flush, Wait. Not bloated, no hidden costs.
  • ๐Ÿงฉ COMPLETE > Dependencies, child jobs, parallel-for, SIMD batches, cancellation and exception handling are included.
  • ๐Ÿšข SUPPORT > Targets .NetStandard 2.1, so it runs on .Net 6 and 8 and may be used with Unity or Godot!

Download the package and get started today!

dotnet add PROJECT package ZeroAllocJobScheduler --version 2.0.0

โฉ Quickstart

Let's say you want to run some work on all your cores... sounds complicated? It's not! Create a scheduler, schedule a job, flush it and wait for it.

using Schedulers;

// A job is a class or a struct
public struct HelloJob : IJob
{
    public void Execute() => Console.WriteLine("Hello from a worker!");
}

using var scheduler = new JobScheduler();           // one worker per processor

var handle = scheduler.Schedule(new HelloJob());    // prepares the job
scheduler.Flush(handle);                            // hands it to the workers
scheduler.Wait(handle);                             // returns when it is done, and helps working meanwhile

Keep one scheduler for the lifetime of your program. Creating it is the only part that allocates. Jobs can be structs or classes.

๐Ÿ’ก Highlights

That is all you need to start. If you want to know more about the techniques under the hood, read how it works. There's more to explore, for example...

๐Ÿค Our promise

  • Bare minimum - No overengineering, no hidden costs
  • Incredibly fast and allocation free
  • No busy waiting, an idle scheduler uses no CPU
  • Every feature is tested, including stress tests for the threading code

๐Ÿš€ Features

  • Jobs as classes or as structs, without boxing
  • Dependencies: a job can wait for any number of other jobs
  • Child jobs: wait for a parent and you wait for its children
  • Parallel-for over ranges, with optional SIMD batches
  • Cancellation of jobs, including children and dependents
  • Exceptions in jobs do not kill workers, and surface where you wait
  • Safe, recycled handles: old handles are recognized
  • Idle policy that adapts to your machine, and can be replaced
  • And much more...

๐Ÿ”— Dependencies and children

var load = scheduler.Schedule(new LoadJob());
var physics = scheduler.Schedule(new PhysicsJob());
var render = scheduler.Schedule(new RenderJob());
scheduler.AddDependency(render, load);              // render waits for load AND physics
scheduler.AddDependency(render, physics);

scheduler.Flush(load);                              // flush the jobs without dependencies, the rest follows
scheduler.Flush(physics);
scheduler.Wait(render);

var parent = scheduler.Schedule(new ParentJob());
var child = scheduler.Schedule(new ChildJob(), parent);   // waiting for the parent also waits for its children
scheduler.Flush(parent);
scheduler.Flush(child);
scheduler.Wait(parent);

๐Ÿงฎ Parallel-for

using Schedulers.Utils;

public struct Scale : IJobParallelFor
{
    public float[] Data;
    public void Execute(int index) => Data[index] *= 2f;
}

var data = new float[100_000];
var handle = scheduler.ScheduleParallelFor(new Scale { Data = data }, data.Length);
scheduler.Flush(handle);
scheduler.Wait(handle);

Implement IJobParallelForBatch and use ScheduleParallelForBatch to receive Execute(int start, int count) with whole batches, for example to work with SIMD. Like every other handle, the result can be waited for, cancelled and used for dependencies.

๐Ÿ›‘ Cancellation

scheduler.Cancel(handle);                           // skips jobs that did not start, including children and dependents

if (scheduler.IsCancelled(handle)) return;          // lets a running job stop by itself, when it has its handle

๐Ÿ’ฅ Exceptions

try { scheduler.Wait(handle); }
catch (AggregateException e) { /* the exceptions of the jobs that threw */ }

scheduler.JobExceptionHandler = exception => Console.WriteLine(exception);   // or get notified right away

๐Ÿ˜ด Idle workers

Workers without jobs look for work for a short time and then sleep. How long is chosen from the wake-up time of your machine. To override that:

using Schedulers.Idle;

var scheduler = new JobScheduler(0, new FixedIdleSpinPolicy(TimeSpan.FromMilliseconds(0.1)));   // or your own IIdleSpinPolicy

๐Ÿš€ Performance

The scheduler is built for the jobs of a game frame: many small ones, a few big ones, and a lot of parallel-for. Care is taken to find a healthy balance between CPU performance, memory and an idle machine.

Scenario NuGet 1.1.2 Now
20,000 independent jobs 68.8 ms 4.2 ms 16x
One job that waits for 1,000 jobs 5.2 ms 0.35 ms 15x
100 parallel-fors of 2,000 elements, like a frame of queries 10.4 ms 2.0 ms 5x
Parallel-for over 1,000,000 elements 1.8 ms 0.29 ms 6x
Chain of 20,000 dependent jobs 21.4 ms 7.8 ms 2.7x
First job after a pause of 2 ms 250 us 53 us 5x
Allocation for 20,000 struct jobs 480 KB 0
CPU usage while idle 0 0

Measured against the last NuGet release with BenchmarkDotNet on one laptop, so take the numbers as an order of magnitude.

Compared with Parallel.For, Task and the ThreadPool it allocates nothing where they allocate kilobytes to megabytes, and it is faster for large ranges and for many queries at once. It is not faster everywhere: ThreadPool work items are a bit faster for 1,000 empty jobs, and Task.ContinueWith chains that run inline beat a short chain of dependent jobs.

Have a look at the benchmarks for all scenarios, and how they were measured!

๐Ÿ“– Documentation

  • ๐Ÿ” How it works > What happens to a job, and why it is fast.
  • ๐Ÿ“Š Benchmarks > Every scenario, compared with the last NuGet release.

โš ๏ธ Good to know

  • At most 65,535 jobs can be scheduled and unfinished at the same time.
  • Handles are recycled once their job has finished. Using an old handle is safe: waiting for it returns at once, cancelling it does nothing and flushing it throws.
  • Wait also executes jobs on the calling thread, which may include jobs you did not wait for.
  • Running jobs are never interrupted, cancellation is cooperative.
  • The tests and benchmarks ran on Linux x64 with .Net 8 so far. ARM64 and Windows are not covered yet.
  • IParallelJobProducer and ParallelJobProducer<T> still work but are obsolete. Use IJobParallelForBatch instead.

๐Ÿ› ๏ธ Contributing

Found a bug, or have an idea? Open an issue or a pull request! The solution contains the tests (JobScheduler.Test) and the benchmarks (JobScheduler.Benchmarks, and JobScheduler.Benchmarks.Baseline for the NuGet package). Please run the tests before you send a pull request, they include stress tests for the threading code. Every push is built and tested on Linux, Windows and macOS. A pull request with the label benchmark also runs the benchmarks. A release is made by starting the workflow by hand: enter the version and the release notes, and choose to publish. It pushes the package to NuGet and GitHub, and creates the GitHub release.

๐Ÿ“„ License

Apache 2.0, see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on ZeroAllocJobScheduler:

Package Downloads
Arch

A high performance c# net.7 and net.8 archetype based ECS ( Entity component system ).

LayerBase

้ซ˜ๆ€ง่ƒฝไธ€ไฝ“ๅŒ–ๆธธๆˆๆžถๆž„ๆก†ๆžถใ€‚้›†ๆˆๆจกๅ—ๅŒ–ๅฑ‚็บงใ€่ฝป้‡็บง DIใ€ๅผ‚ๆญฅไปปๅŠก(LBTask)ไธŽ่ถ…ๆž้€Ÿไบ‹ไปถๆ€ป็บฟใ€‚ไธ“ไธบ Godot/Unity ไผ˜ๅŒ–ใ€‚

Pixillery.Core

The core library for the Pixillery game engine which all other Pixillery engine packages depend on.

ABEngine.Arch

A high performance c# net.6 and net.7 archetype based ECS ( Entity component system ).

ZeroGdk.Server

A high-performance C# library that powers the server side of the ZeroGdk framework, offering advanced connection management, an Arch-based ECS, and real-time entity networking for scalable multiplayer game servers.

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on ZeroAllocJobScheduler:

Repository Stars
genaray/Arch
A high-performance C# based Archetype & Chunks Entity Component System (ECS) with optional multithreading.
genaray/Arch.ZeroAllocJobScheduler
A high-performance alloc free c# Jobscheduler.
annulusgames/Arch.Unity
Arch ECS integration for Unity.
Version Downloads Last Updated
2.0.1 0 11/27/2026
2.0.0 57 11/26/2026
1.1.2 173,878 3/13/2024
1.1.1 594 11/22/2023
1.0.2 16,164 11/12/2022
1.0.1 1,667 11/12/2022
1.0.0 719 11/12/2022