Skip to content

perf: lockfile lookup in O(depth), and LTO release builds - #201

Merged
sweepies merged 4 commits into
mainfrom
perf/allocator-release-profile
Nov 8, 2026
Merged

sweepies merged 4 commits into
mainfrom
perf/allocator-release-profile

Conversation

@sweepies

@sweepies sweepies commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

What

  • perf(update): lockfiles::nearest scanned every path in the tree for each update it planned. The npm bun.lockb and 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/we vs apps/web, locks below a file, the root).
  • perf: [profile.release] with lto = "fat" and codegen-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:

main lockfile fix fix + LTO
policy phase ~2.2 s ~0.25 s ~0.23 s
user CPU ~2.47 s ~0.55 s ~0.51 s
wall ~9.2 s ~7.5 s ~7.1 s
peak RSS ~133 MB ~134 MB ~131 MB
binary 39.8 MB 39.8 MB 31.6 MB

perf on main put about 65% of a warm run's CPU in nearest/job, and the same planning code runs in run.

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 digest phase, about 5 s of the remaining ~7 s, and it's a serial chain:

  1. GraphQL tag-digest wave (~1.2 s) → REST /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.
  2. REST /commits/{tag} calls that return 422 (e.g. actions/upload-artifact/commits/4.6.2) are never cached, so every warm run asks again.

View guided diff Turn on auto-fix

`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.

@olivia-colomar-app olivia-colomar-app Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¡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 build job — margin confirmed, first tagged release to be watched. Resolved.
  • Unstripped artifacts (P4): sweepies verified the musl release binary already has no symbol table (strip leaves it at exactly 31,602,336 bytes), so strip = "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).

Comment thread Cargo.toml Resolved
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.
@sweepies

sweepies commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Thanks, Olivia. On the two P4s:

  • Fat-LTO build time: a cold x86_64 musl build with the new profile took about 6 minutes on a 4 vCPU VM, so two targets back to back come to roughly 12–15 minutes against the 60-minute build job. That leaves plenty of margin; I will check the first tagged release.
  • strip: the release binary already has no symbols (replied inline), so there is nothing to remove.

Separately, Tests: unit (update) failed on plans_regenerate_lockfiles_side_by_side. That test came in with #187, and it relied on two tool runs overlapping within a fixed 50 ms sleep, which a slow runner can miss. It now holds each tool run until a second one starts (up to 5 s), so the result no longer depends on runner speed, and serialised plans still fail it. Fixed in the latest commit.

@olivia-colomar-app olivia-colomar-app Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@/tmp/tmp.PZqDqeDukW/prev-review.md

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.

@olivia-colomar-app olivia-colomar-app Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¡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_use is load-bearing, and correct. installed() gates purely on the usage record's tool@version keys, so pre-marking go@<defaults pin> makes each tool() call skip the lock_store(exclusive) + clear_unproven + seed block and take only the shared lock. Without it the three plans would serialize on the exclusive lock — and clear_unproven's mise uninstall would itself count as a "tool" run in Overlap (no git arg) and burn its own 5 s deadline. The version matches exactly: versions["go"] falls back to the defaults.toml pin (1.27.3), which go_version keeps because it beats the fixture go.mod's go 1.21 directive, and default_version("go") reads the same pin.
  • assert_eq!(most, 3) proves full overlap. most is fetch_max of the live active count, so 3 means three tool calls were genuinely in flight at once — a regression capping prepare_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_use runs synchronously before prepare_all, so it can't race the plans. The finished and lockfiles_ready assertions 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.

@sweepies

sweepies commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Thanks! I'll leave the go pin coupling as it is. The default pin is 1.27 against the fixture's go 1.21, and as you say, a mismatch would fail loudly rather than pass silently.

@sweepies
sweepies merged commit 02d3f4c into main Nov 8, 2026
11 checks passed
@sweepies
sweepies deleted the perf/allocator-release-profile branch November 8, 2026 18:07
@sweepies-ops sweepies-ops Bot mentioned this pull request Nov 8, 2026
sweepies added a commit that referenced this pull request Nov 10, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant