ADR-0120: The local loop takes a share of the machine and looks only at what changed
Status: Accepted
Date: 2026-11-09
Amends: 0010: how watch looks for a change, how often, and what a round prints as it runs
Amends: 0078: the priority a daemon starts at, and how it waits while idle
Amends: 0023: how a warm worker and its client wait for each other, and how many workers a set boots
Context
watch (ADR-0010) and the daemon of serve (ADR-0078) run on the machine a
person works at, beside their editor, browser and builds. They ran as a CI
job does:
- every look at the files listed every file with
git ls-filesand hashed all of them, about 0.6 CPU-s on a tree of 5,800 files, once a second, and a round took one look before each batch and three more after it; - a coverage run of one test file, the one a save usually moves, started Pest with paratest across every core; each pool of warm workers booted one worker for each place however few runs it had; Pest listed the tests twice each round;
- every process ran at normal priority on every core, on battery as on power;
- an idle daemon woke every second, and a warm worker and its client looked at their files a hundred times a second;
- a round printed nothing until its verdict.
run, pre-push and CI run as many workers as runner.* says, as before;
a pre-push the daemon serves runs at the priority the daemon was started
at.
Decision
- A look asks
git statuswhat differs.watchrunsgit --no-optional-locks status --porcelain=v2 -z --untracked-files=all, which answers from the index's stat cache and takes no lock the user's own git commands could meet, and hashes only the paths that differ from the commit, tracked or not, and those that differed at the last look. Every other file holds what the commit holds, as it did at the last look. A look at another commit than the last, and the first look, list and hash every file.local.watchStatus: falsehashes every file at every look. - One look a wait. While a round runs,
watchlooks for a change before a batch only oncelocal.watchPollhas passed since its last look, and keeps the change it found; once the round is over, it takes at most one look more.local.watchPollis2sby default. - The local loop takes a share of the machine.
local.cpuisbalanced(half the logical cores, at least one and at most eight, at utility priority),fast(every core but one, at normal priority) orquiet(one worker at background priority);balancedby default.local.workers(a count,halforall-but-one) andlocal.priority(normal,utility,background) set either part on its own, and each platform's class of the priority is a key of its own:local.macosClass(ataskpolicyQoS clamp:none,utility,background,maintenance),local.linuxNice(0 to 19) andlocal.windowsClass(normal,below-normal,idle).- The workers drive a round's coverage run, its pools, how many mutants
Pest runs at once and how many children the opcache equivalence check
compiles in. The gate's Pest plugin sets the count in
pest-plugin-mutate's command-line configuration, patched or not, so
neither Pest, which refuses
--processeson a mutation run, nor a mutant's own run is handed the option. watchlowers its own process, which every process a round starts inherits: a niceness on Linux and macOS, which a process can raise and never lower again;taskpolicy's darwin background on macOS for the background and maintenance classes, set and taken back as the class asks; a priority class on Windows. A running process cannot be put under the utility QoS clamp, sowatchrunning on its own takes the utility niceness there; the daemonwatchstarts is launched undertaskpolicy -c <clamp>on macOS andnice -n <niceness>on Linux, and everything it serves inherits that.
- The workers drive a round's coverage run, its pools, how many mutants
Pest runs at once and how many children the opcache equivalence check
compiles in. The gate's Pest plugin sets the count in
pest-plugin-mutate's command-line configuration, patched or not, so
neither Pest, which refuses
- On battery or in Low Power Mode,
local.onBatterydecides:reduce, the default, runs a round on one worker at background priority;pauseholds the next round until the machine runs on power, saying so once;runchanges nothing.pre-pushandrunare never held. The power source is read frompmseton macOS,/sys/class/power_supplyand the ACPI platform profile on Linux, and PowerShell'sWin32_Batteryon Windows. PHP is told of no change without native code, sowatchreads it at the start of each round, and at each wait while it holds one; a source it cannot read is taken as mains. - Output-neutral speed-ups, each its own key and on by default:
local.coverageAlone: a coverage run of one test file runs in Pest's own process, and a coverage run given one process runs without paratest;local.sizedPools: a set of warm workers boots no more workers than it has runs, the tail's sets and the native runner's workforce alike;local.listOnce: Pest's listing and its test names are remembered by the digest of the files in the test directories, whichwatchsets each round, so a round lists the tests only where a test file was added, changed or removed, and a changed one is listed again;local.streamBatches:watchprints, as each batch ends, how many mutants it judged by status and where each survivor is, before the round's verdict. Output for an editor's problem matcher is unchanged.
- Waits block. With no child running, the daemon waits for a request
for the whole idle time left. A warm worker and its client pause by
blocking on a pipe of their own that each wake signal writes a byte to,
so a wake that comes just before a pause ends it at once. A pause no wake
cuts short ends at its interval, which is how a worker or a client notices
the other went away:
local.childWait(1s) in the local loop, andrunner.pollin a run.
Alternatives considered
- Native file events in PHP. PECL
inotifyis Linux only; the other watchers need fswatch or Node. The Rust core's watcher replaces the look later;git statusremoves most of a look's cost without a new binary. - A stat cache in place of hashing what differs. PHP's
statreports modification times in whole seconds, so two saves of the same size within a second would read as one. Hashing what git lists stays exact. - Re-executing
watchundertaskpolicy -c. It would lose-doptions given to PHP on the command line; the daemon, which the gate starts itself, is launched under the clamp instead. - Every core by default. Fastest, and it competes with the work the
person waits on; it is
local.cpu: fast.
Consequences
- On this repository's 5,825 files, a look's CPU fell from 0.59 s to 0.22 s
(median of 7, load 16 to 18); on the quick-start fixture from 0.042 s to
0.022 s. With the wait at 2 s, an idle
watchon a tree that size looks at about a tenth of a core's worth in place of about a third. - On a machine with 8 logical cores, a round runs on 4 workers at utility priority by default.
- A niceness raised on Linux or macOS, on battery under
reduceor bylocal.linuxNice, stays raised untilwatchrestarts. - A vendor an earlier gate patched holds another gate's patch, which
composer reinstall pestphp/pest-plugin-mutateandpest:patchreplace.