module

Noir::WorkerThreads

A small pool of threads for work that is a pure function of its input.

Crystal 1.21 runs every program on the execution-context runtime, so noir can put fibers on other threads without new compile flags. Only pure work goes here — reading a file, parsing a source into a fresh result — never anything that touches CodeLocator, an analyzer's instance state or the logger. Callers keep everything stateful on their own fiber and consume the pool's results in their original order, which is what keeps a scan's output independent of thread timing.

Constants

MAX_THREADS = 4

Past four threads the measured gains flatten out (file reads on a 26k-file tree: 1.29s sequential, 0.46s with 4, 0.40–0.44s with 8).

Class methods

context

One context for the process, created on first use. Contexts are not torn down, so a per-call context would leak threads across the many scans a spec run performs.

Source
count
Source
map(items : Array(T), &block : T -> U) : Array(U | Nil) forall T, U

block applied to every element of items on the pool, returned in input order.

An element whose block raises comes back as nil. That makes this an optimisation callers can fall back from: they recompute a nil element on their own fiber, where it raises (or not) exactly as it always did.

Source
spawn(name : String, &block : -> ) : Nil
Source
spawn_walker(name : String, &block : -> ) : Nil
Source
walk_context

A second context for the detect walk's directory listings. They are what the walk waits on next, so they must not queue behind the file reads the walk itself keeps feeding into context.

Source