Evaluating a change's required checks takes seconds, not minutes
State
free to start
Created
2026-11-03 by contributor
Body
Measured from worker telemetry (`eval.end`). Before a batch builds anything, attest evaluates every required check in one shared `nix eval`:
- the-valley: 30–94 s (29.7 s for ovrm v3 on 2026-11-03; a median of 85 s over 2026-11-02);
- a downstream project: 123–157 s (123 s for wnzs on 2026-11-03).
With outputs kept (bd-51b089c) and checks trimmed (oc-19345de), evaluation is now often the largest part of a batch for a small change. ovrm v6's whole batch was 78 s. The abandoned oc-1e43ec2 tried evaluating in groups side by side.
Outcome: evaluating a change's required checks costs a few seconds when the inputs they read did not change. One way is to cache derivation paths by the inputs each check reads. Another is to evaluate only the checks the change requires, and not the whole flake's check set. Measure first: which part of the evaluation dominates.
Comments
contributor2026-11-03 22:22 UTC
Measurement, 2026-11-03: where a batch's evaluation time goes. Part 1 of 2: the numbers.
In short, one check dominates each project's evaluation, and in both projects that check evaluates many NixOS systems. In the-valley, `module-eval` is about 15 s of a 25 s evaluation. In the downstream project, `eval` is about 50 s of a 90 s evaluation. Part 2 has the cache findings and a ranked recommendation.
## Method
- Per-check timings ran in a guest with 8 CPUs, 16 GiB of memory and nix 2.34.9. Evaluations ran one at a time over a tree exported with `git archive`, which is how attest exports a tree.
- "Alone" means `nix eval --raw <tree>#checks.x86_64-linux.<name>.drvPath`. attest runs this command for a check it evaluates on its own (evalClosure in attest/check.go).
- "Combined" means attest's own evalDrvPaths expression over the named set: `nix eval --json --apply '<listToAttrs … tryEval … drvPath>' <tree>#checks.x86_64-linux`.
- Memory is the evaluator's peak resident set, in GiB.
- The guest's combined times are close to the host's. For the same check sets: the-valley's ktmv v2 took 24.1 s on the deployment host and 26.9 s in the guest. The downstream project's qrxk v1 took 101.4 s on the host and 91.7 s in the guest.
## 1. Today's numbers
These are worker telemetry `eval.end` records, field `eval_ms`, for every batch on 2026-11-03 (UTC): 32 batches in all.
| project | batches | min | median | max | total |
|---|---|---|---|---|---|
| the-valley | 27 | 15.6 s (ovrm v3, 01:47) | 19.5 s (smuk v2, 14:41) | 30.3 s (tvun v2, 14:41) | 548 s |
| downstream | 5 | 1.6 s (zsmn v2, one check) | 117.7 s (wnzs v2, 17:08) | 123.6 s (wnzs v1, 14:22) | 468 s |
- Without zsmn's one-check batch, the downstream range is 101.4 s (qrxk v1) to 123.6 s.
- Evaluation is most of a downstream batch whose builds are cached. It took 117.7 s of wnzs v2's 125.7 s batch (94%) and 101.4 s of qrxk v1's 152.2 s batch (67%).
- the-valley's evaluation time barely depends on how many checks a batch names. yonw v1 named 7 checks and took 18.9 s. ktmv v2 named 32 and took 24.1 s.
- All 27 of the-valley's batches required module-eval. 4 of the downstream project's 5 batches required `eval`.
- ovrm v3 (head 9fed0a0) was evaluated five times on 2026-11-03, at 15.6 to 29.6 s each. Its head had already been evaluated on 2026-11-02. Those five repeats are 93 s of the-valley's 548 s.
## 2. Where it goes
### the-valley at bd760cae (main): 63 checks
Each check evaluated alone, slowest first:
| check | alone | memory |
|---|---|---|
| module-eval | 18.0 s | 3.7 GiB |
| ssh-e2e | 5.1 s | 0.9 |
| web-publisher-e2e | 3.5 s | 0.6 |
| publish-e2e | 3.2 s | 0.6 |
| telemetry-e2e | 3.1 s | 0.6 |
| worker-e2e | 3.1 s | 0.6 |
| restack-host-e2e | 2.9 s | 0.6 |
| signers-e2e | 2.2 s | 0.6 |
| 19 more NixOS tests and evaluations | 1.0 to 1.9 s each | 0.2 to 0.4 |
| the other 36 checks | 0.3 to 1.0 s each | 0.1 to 0.2 |
The cheapest check takes 0.31 s alone. That is the floor every check shares: reading the flake and its lock, and importing nixpkgs. Listing the check names takes 0.08 s.
attest's combined evaluation, for the sets real batches named:
| set | checks | combined | sum of alone | memory |
|---|---|---|---|---|
| every check | 63 | 26.5 s | 85.9 s | 6.2 GiB |
| ktmv v2 | 32 | 26.9 s | 64.0 s | 6.0 |
| wywq v1 | 17 | 24.0 s | | 5.6 |
| yonw v1 | 7 | 19.6 s | | 4.7 |
| ktmv v2 without module-eval | 31 | 12.2 s | 46.0 s | 2.4 |
| module-eval with cue-vet | 2 | 16.0 s | | 3.7 |
- module-eval costs 14.7 s of ktmv's 26.9 s (55%). It evaluates about 31 NixOS systems, one per host in nix/checks/hosts.nix, at roughly 0.5 s each. The hosts share their package set and nothing else.
- The other 31 checks share well. They take 46 s evaluated one by one and 12.2 s together. What they do not share is each NixOS test's own node configurations, which cost 1 to 5 s per test.
### The downstream project at 4b95213 (main): 36 checks
Each check evaluated alone, slowest first:
| check | alone | memory |
|---|---|---|
| `eval` | 51.5 s | 6.8 GiB |
| the `*-rebuild-vm` link farm of the four VM tests | 36.2 s | 5.4 |
| each of the four `*-rebuild-vm-*` VM tests | 27.6 to 28.6 s | 4.3 |
| the three `toplevel-*` checks | 14.0, 11.1 and 4.9 s | 1.8, 1.5, 0.8 |
| eight NixOS tests and evaluations | 3.5 to 5.4 s each | 0.6 to 1.0 |
| the other 19 checks | 0.3 to 2.3 s each | 0.1 to 0.5 |
attest's combined evaluation:
| set | checks | combined | sum of alone | memory |
|---|---|---|---|---|
| qrxk v1 | 15 | 91.7 s | 209.6 s | 12.1 GiB |
| wnzs v2 | 23 | 93.1 s | 225.8 s | 13.0 |
| qrxk v1 without `eval` | 14 | 63.1 s | 158.0 s | 8.4 |
| `eval` with fmt | 2 | 49.7 s | | 6.8 |
| `eval` and the three `toplevel-*` | 4 | 50.5 s | 81.5 s | 6.8 |
| the four `*-rebuild-vm-*` tests | 4 | 35.9 s | 112.1 s | 5.4 |
| the three `toplevel-*` | 3 | 23.3 s | 30.0 s | 3.1 |
- `eval` evaluates every NixOS system and every Linux home configuration (checks/default.nix). The `toplevel-*` checks come almost free next to it: `eval` alone takes 49.7 s, and with the three toplevels 50.5 s.
- The four VM tests share most of their work: 112 s evaluated one by one, 36 s together.
- The shared floor is 0.33 s.
### Other observations
- **Memory.** One combined evaluation of the downstream project peaks at 12.1 to 13.2 GiB, and one of the-valley at 6.0 to 6.2 GiB. Since bd760cae the worker builds several changes at once. Two downstream batches evaluating at the same moment would need about 25 GiB.
- **Garbage collection is not a lever.** GC took 6.7 s of qrxk's 109 s of evaluation CPU (6%), so a larger initial heap would save little.
contributor2026-11-03 22:22 UTC
Measurement, 2026-11-03. Part 2 of 2: whether evaluation can be skipped for an unchanged check, the other levers, and a ranked recommendation.
## 3. nix's flake evaluation cache
nix's cache can make a repeat evaluation of the same commit cost 0.05 s. attest's evaluation never uses it today. Even used the right way, the cache is keyed by the whole commit, so a check that did not change still costs full price in a new commit.
This test evaluated module-eval at bd760cae. Each command ran twice in a row:
| how it was evaluated | first run | second run |
|---|---|---|
| `nix eval --raw <exported dir>#checks.x86_64-linux.module-eval.drvPath` (attest's per-check form) | 14.6 s | 14.3 s |
| `nix eval --raw git+file://<repo>?rev=<rev>#….module-eval.drvPath` | 14.6 s | 14.8 s |
| `nix path-info --derivation <exported dir>#….module-eval` | 15.1 s | 0.06 s |
| the same, from a second export of the same commit into another directory | 15.1 s | |
| `nix path-info --derivation git+file://<repo>?rev=<rev>#….module-eval` | 15.0 s | 0.03 s, then 0.03 s |
What the test shows:
- **`nix eval` never reads the cache.** It evaluates the final value in full. So neither attest's per-check `nix eval --raw ….drvPath` nor its combined `nix eval --apply` over `checks.<system>` can hit it.
- **Commands that ask for a derivation do read it.** `nix path-info --derivation` (and `nix build`) read `drvPath` from the cache, which stores it per attribute path.
- **A path flake hits only from the same directory.** attest exports each run into a fresh temporary directory (MkdirTemp in attest/run.go), so it would always miss, even with path-info. A locked `git+file` reference at a revision hits across directories and across runs.
- **Several checks in one command still share one evaluation, and each is cached on its own.**
- the-valley, ktmv's 32 checks at 9a7e5066: 22.3 s cold (4.5 GiB), 0.05 s warm. The same 32 plus three uncached checks: 0.58 s.
- downstream, qrxk's 15 checks at 4b95213: 93.9 s cold (12.1 GiB), 0.07 s warm. wnzs's 23, with qrxk's 15 already cached: 8.3 s.
- A cold multi-check `path-info` is no slower than attest's combined `nix eval --apply`: 22.3 s against 26.9 s for the-valley, and 93.9 s against 91.7 s downstream.
- **The cache key is the whole flake: the locked source, which is the commit, and the lock file.** module-eval names the same derivation at bd760cae and at 9a7e5066. It was cached at bd760cae, and ktmv's set at 9a7e5066 still took 22.3 s cold.
### How often the same commit is evaluated again
On 2026-11-03 the worker evaluated an already-evaluated head 5 times, all ovrm v3. That is 93 s of the-valley's 548 s (17%). The downstream project had no repeats (0 of 468 s).
### How often a check is unchanged
These numbers come from every check's derivation at consecutive commits on main, compared with the commit before.
- **the-valley.** Over 8 consecutive commits up to bd760cae, each commit changed 6 to 35 of the 63 checks. module-eval's derivation never changed. Evaluating only the checks that changed costs:
| commit | checks changed | evaluating only those |
|---|---|---|
| bd760cae, all changed checks | 28 | 9.5 s |
| bd760cae, the changed checks in ktmv's set | 24 | 8.5 s, against 26.9 s for the whole set |
| 9a7e5066 | 7 | 5.0 s |
| 16d422ff | 6 | 5.6 s |
- **The downstream project.** This compared 3 commits over qrxk's 15 checks.
- The two lock bumps that adopt a the-valley commit each changed 4 checks: `eval` and the three `toplevel-*`. The four VM tests were unchanged. Evaluating only the changed four: 50.5 s, against 87 to 93 s.
- A change to its checks (4802056) changed 8 checks, but not `eval`. Evaluating only those 8: 41.5 s.
So a perfect per-check cache would cut the-valley's evaluation by 65 to 80%, and the downstream project's by 45 to 55%. The downstream floor stays at `eval`'s 50 s whenever any system changes.
### What a per-check cache would take
nix records no set of inputs per attribute. To key a check by the inputs it reads, attest would need one of two things:
- (a) Evaluate each check from a tree holding only the files that check declares. This works only if every check takes its sources through filesets and never through `self`, because `self.outPath` changes whenever any file does.
- (b) Trace the files each check reads. Attributing reads to a check needs one evaluation per check on every miss. That costs 64 s against 27 s combined for the-valley, and 210 s against 92 s downstream.
Either way, attest would sign a derivation it did not evaluate for that tree, so a wrong key produces false evidence. Estimate: 400 to 800 lines across attest and both projects' flakes.
### oc-90b6f14
oc-90b6f14 proposes attest's own cache, keyed by (tree, check, system, evaluator), to skip evaluation when the same tree is evaluated again. nix's cache gives the same effect with less code. Evaluated as `git+file` at a revision, nix keys the cache by the commit and the lock. That settles two of oc-90b6f14's traps:
- Trap 1: `lastModified` becomes the commit's time.
- Trap 2: nix does not cache a flake whose lock is unlocked.
Trap 3 (inherited nix configuration) and trap 5 (the cache is signing input) remain.
It is still a same-commit cache. Today it would save 17% for the-valley and nothing for the downstream project. It is worth doing for its cost, but it does not meet this outcome.
## 4. Other levers
- **Evaluating only the required checks: attest already does this.** eval.start names only the batch's required checks: 7 to 33 of the-valley's 63, and 15 to 23 of the downstream project's 36. The apply expression forces only those attributes, and listing the names costs 0.06 to 0.08 s. Little is left to gain here. All 63 of the-valley's checks take 26.5 s, ktmv's 32 take 26.9 s, and yonw's 7 take 19.6 s, because module-eval is in every set.
- **What the-valley's checks structure costs.** Little beyond module-eval. nix/checks.nix hands every check one shared package set, so the shared floor is 0.3 s. The 31 checks of ktmv's set other than module-eval evaluate in 12.2 s together. The real cost is NixOS evaluations: module-eval's 31 hosts, and each NixOS test's nodes.
- **What requires module-eval.** In the-valley's policy (policy/project/policy.cue), the `nix` class requires module-eval for every path under `nix/**`, plus `flake.nix`, `flake.lock` and the host examples. The telemetry class requires it too. A change to one check's script or definition under nix/checks/ matches both that check's own class and the `nix` class, so it pays for module-eval as well. module-eval renders the module against stand-in programs. nix/checks/host-module.nix says it changes only when the module, a host declaration or the check itself changes. Its unchanged derivation over 8 consecutive commits agrees.
## Ranked recommendation
1. **the-valley: require module-eval only where it can change.** Narrow the `nix` class from `nix/**` to the module's own files, the host declarations, `flake.nix` and `flake.lock`. Leave the files under nix/checks/ to their per-check classes, and keep own-policy required for check definitions.
- Saving: about 15 s of a 25 to 27 s evaluation (12.2 s instead of 26.9 s for ktmv's set), for every change that touches none of those files.
- Cost: about 10 to 20 lines of policy.cue, and no code.
- Risk: a path left out lets a change that alters module-eval land without it.
2. **attest: evaluate through nix's cache.** Replace evalDrvPaths' `nix eval --apply` over the exported directory with one `nix path-info --derivation` over `git+file://<repo>?rev=<head>`, one installable per check.
- path-info prints a set of paths, not one per installable. So read each check's derivation back with a warm per-check `path-info`, at about 0.05 s each.
- Keep the per-check fallback for a set that fails as a whole.
- Check that neither project relies on `export-ignore`: `git archive` honours it, and nix's git fetcher does not by default.
- Saving: every repeat of a commit drops below a second (93 of 548 s for the-valley on 2026-11-03, none downstream). A cold evaluation is no slower.
- Cost: about 60 to 100 lines in attest/check.go, plus real-nix tests in attest/run_test.go.
- This would close oc-90b6f14 in place of attest keeping its own cache. Separately, it is worth finding out why ovrm v3 was evaluated five more times.
3. **the-valley: make module-eval cheaper.** It evaluates about 31 NixOS systems at about 0.5 s each. Fewer hosts, each carrying several scenarios, cut its time roughly in proportion.
- Saving: about 7 s per batch that still requires it, if the hosts are halved.
- Cost: medium, a rework of parts of nix/checks/hosts.nix and nix/checks/host-module.nix (1,876 lines together).
4. **The downstream project: its floor is `eval`, 50 s,** whenever any system changes. Only that project's own policy can narrow when `eval` and the four VM tests (36 s together) are required. Its saving and cost are for that project to judge. The four VM tests did not change across either lock bump measured here.
5. **A per-check cache keyed by each check's inputs.** It saves the most (65 to 80% for the-valley, 45 to 55% downstream). It needs a sound per-check input set, which nix does not provide, and an argument for signing a derivation that was not evaluated. Estimate: 400 to 800 lines. Not now.
6. **Evaluating in parallel groups (oc-1e43ec2).** The floor would be module-eval's 16 s in the-valley (from 27 s) and `eval`'s 50 s downstream (from 92 s), for about 480 lines. Each extra process needs its own memory: `eval` alone takes 6.8 GiB. Not recommended.
With 1 and 2, most of the-valley's batches would evaluate in about 10 s. The downstream project stays near 90 s per batch unless 4 or 5 is taken.
contributor2026-11-03 22:25 UTCedited2026-11-04 00:27 UTC by contributor
Decisions, 2026-11-03 22:25Z, from the measurement above. Launched: (a) evaluations take turns across concurrent batches, so two never exceed the slice's 16G together (a downstream project's evaluation peaks at 12–13 GiB, the-valley's at about 6 GiB): run 20261103-2225-0d9d18e4; (b) recommendation 1, module-eval required only where it can change: run 20261103-2225-4c27c85d; (c) recommendation 4 in the downstream project, `eval` split per host with narrowed triggers: run 20261103-2225-5ef97627. Next: recommendation 2 (attest evaluates through nix's cache via git+file, closing oc-90b6f14). Deferred: 3 (fewer module-eval hosts), 5 (a per-check input cache) and 6 (parallel groups, not recommended).
contributor2026-11-08 22:28 UTC
Carried from oc-90b6f14, which ends as a duplicate of this outcome: the eligibility traps any reuse of an evaluation must solve.
1. Exported trees get fresh mtimes, visible as `self.lastModified`, so the same tree digest can evaluate differently (attest/run.go, attest/git.go).
2. Evaluation runs without `--no-update-lock-file`, so a missing or stale lock can resolve changing inputs (attest/check.go).
3. Inherited nix configuration (`NIX_CONFIG`, includes, accepted flake config) changes evaluation, and `nix --version` alone does not identify the evaluator.
4. Import-from-derivation makes reuse depend on imported outputs.
5. Store validity of a cached `.drv` does not prove it belongs to the key, so a cache becomes trusted signing input.
6. Real-nix tests live in attest/run_test.go with `ATTEST_NIX_TESTS=require`; check discovery also evaluates (attest/run.go).
7. Evidence equality is compared at identical revision, signer and provenance.
The cost it addresses: an approval of a downstream project's change ran 22 nix checks, and each one that built nothing still took 72 to 73 s, about 26 minutes spent evaluating the same tree 22 times.