Repository navigation
perf: lockfile lookup in O(depth), and LTO release builds - #201
Conversation
`nearest` scanned every path in the tree for each update it planned, and the lockfile checks for npm and NuGet scanned it again. On grafana that made report assembly 2.2 s of CPU per warm lookup. Walking up the file's parent directories and probing the path set gives the same directory in O(depth); NuGet's subtree check reads only the sorted range under the project. Warm lookup of grafana, mastodon and sentry: policy 2.2 s to 0.25 s, user CPU 2.5 s to 0.55 s.
About 7% less CPU on a warm lookup and a 20% smaller binary (39.8 MB to 31.6 MB for x86_64 musl), at the cost of slower release builds.
There was a problem hiding this comment.
¡Ja ja! Found it — that O(tree) scan was hiding in plain sight. Ahora sí, let's see what you've got.
Reviewed e9aa4c9 (live head). The nearest rewrite walks up from directory(file) probing node::join(dir, name), which returns exactly the same answer as the old max-by-depth filter: the candidate set in both versions is the ancestor-or-self directories of file that contain one of names, and string length orders ancestors by depth. subtree's BTreeSet::range(prefix..) + take_while matches the old under(p, dir) prefix test, including the dir == "" whole-tree case, and the bun.lockb probe is a straight contains on the joined path. The new tests pin the prefix-boundary traps (apps/we vs apps/web, locks below the file, the root). No correctness, security, or regression findings.
Findings
P4 — Cold fat-LTO builds now run inside fixed workflow timeouts
lto = "fat" + codegen-units = 1 raises the cost of every cargo build --release. The places that pay: mise run release:package builds both musl targets sequentially under the shared 60-minute build job in release.yml (and a tag's release deliberately restores no cache), patchula.yml's build:cli source builds (60-minute job), build:cli/benchmarks:build locally, and the release-mode cargo test --release benchmark tasks. The timeout margins look fine today, but two back-to-back cold fat-LTO builds are the biggest single jump — worth watching the first tagged release.
P4 — Release artifacts are still unstripped
The binary dropped 39.8 MB → 31.6 MB from LTO alone, but [profile.release] sets no strip. strip = "symbols" would cut it further; skip it only if you want symbols in production cores.
Resolved
- Cold fat-LTO builds (P4): sweepies measured a cold musl build at ~6 min, so two targets come to roughly 12–15 min against the 60-minute
buildjob — margin confirmed, first tagged release to be watched. Resolved. - Unstripped artifacts (P4): sweepies verified the musl release binary already has no symbol table (
stripleaves it at exactly 31,602,336 bytes), sostrip = "symbols"would change nothing. Invalid — resolved inline.
Verification
Read-through review; CI covers the tests (unit, real-tool, and corpus jobs were still running at review time).
plans_regenerate_lockfiles_side_by_side counted overlap across a fixed 50 ms sleep, so a slow runner that set up the next tree after the first tool finished failed it. Each tool now waits, for up to five seconds, until a second one runs; serialised plans still fail.
|
Thanks, Olivia. On the two P4s:
Separately, |
The overlap test hit a tool's first use: each plan first clears an unproven install under the tool store's exclusive lock, which waits for any run holding the shared lock, so whether two runs overlapped was a race. Recording Go as used leaves every plan on the shared lock, and the executor now holds each run until all three have started, so the test asserts full side-by-side regeneration in 40 ms instead of 15 s.
There was a problem hiding this comment.
¡Ja! Tomaste mi sugerencia — and you wired it correctly. Veamos si hay grietas.
Follow-up on 0896e6a (live head). Previous review covered a584a6e; this one covers only the new test-tightening commit, which adopts the earlier P4 — it's folded into Resolved on that comment.
New commit: test(update): prove all three plans regenerate at once, without races
record_useis load-bearing, and correct.installed()gates purely on the usage record'stool@versionkeys, so pre-markinggo@<defaults pin>makes eachtool()call skip thelock_store(exclusive)+clear_unproven+seedblock and take only the shared lock. Without it the three plans would serialize on the exclusive lock — andclear_unproven'smise uninstallwould itself count as a "tool" run inOverlap(nogitarg) and burn its own 5 s deadline. The version matches exactly:versions["go"]falls back to thedefaults.tomlpin (1.27.3), whichgo_versionkeeps because it beats the fixturego.mod'sgo 1.21directive, anddefault_version("go")reads the same pin.assert_eq!(most, 3)proves full overlap.mostisfetch_maxof the liveactivecount, so 3 means three tool calls were genuinely in flight at once — a regression cappingprepare_all's concurrency at 2 now fails instead of passing. The failure costs ~5 s per serialized run in deadlines, then the assert catches it; the updated comment documents both cases.- No new flake vector. The wait still yields (5 ms sleep), keeps the hard deadline, and
record_useruns synchronously beforeprepare_all, so it can't race the plans. Thefinishedandlockfiles_readyassertions are unchanged.
Findings
P4 — the test silently depends on the go pin staying ≥ 1.21
record_use marks go@<defaults pin> while the invocation runs go@max(pin, go.mod directive). The fixture go.mod declares go 1.21, so if a defaults.toml change ever pinned a lower Go, the recorded spec wouldn't match the invocation, installed() would flip false, and the test would fail after ~30 s of store-lock timeouts — loud rather than silent, so risk is low, but the coupling is invisible today. A one-line comment on record_use noting it must match what go_version resolves would close it; take it or leave it.
Verification
Read-through review; CI covers the tests. Lint/hk passed on 0896e6a; unit and real-tool jobs were still pending at review time — plans_regenerate_lockfiles_side_by_side is the check to watch.
|
Thanks! I'll leave the |
…g every path (#234) * perf(update): find the nearest lockfile by walking up, not by scanning every path #221 replaced the directory walk #201 introduced with a filter over every path in the repository, once per dependency. On grafana, mastodon and sentry that put the warm policy phase at 1.3 s instead of 0.3 s. upward now walks from the directory to the root and looks each candidate up; it takes a lookup-only Paths trait, so it cannot scan again. * test(update): pin upward's root-first, name-ordered results
What
perf(update):lockfiles::nearestscanned every path in the tree for each update it planned. The npmbun.lockband NuGet checks scanned it again. It now walks up from the dependency's file and probes the path set. NuGet reads only the sorted range under its project. The answers are unchanged, and new tests pin the boundary cases (apps/wevsapps/web, locks below a file, the root).perf:[profile.release]withlto = "fat"andcodegen-units = 1.Measurements
Static x86_64 musl binaries on the project's boat.dev VM, live warm lookups of grafana/grafana, mastodon/mastodon and getsentry/sentry with
examples/renovate-migration.pkl, five interleaved rounds:policyphaseperfon main put about 65% of a warm run's CPU innearest/job, and the same planning code runs inrun.Tried and dropped
mimalloc as the global allocator: no CPU change, and peak RSS went from about 135 MB to about 310 MB. The static musl binary already links Zig's
SmpAllocator, not musl's mallocng.Follow-ups
After this change, most of a warm lookup's wall time is the
digestphase, about 5 s of the remaining ~7 s, and it's a serial chain:/commits/{ref}→ GraphQL (~1.4 s) → three REST calls back to back → GraphQL (~1.4 s) → Docker HEADs. The Docker HEADs and the GitHub reads don't depend on each other and could overlap. With proper overlap the phase could take about 1.4 s./commits/{tag}calls that return422(e.g.actions/upload-artifact/commits/4.6.2) are never cached, so every warm run asks again.