Repository navigation
Signposts on the app's hot paths, HeedCore benchmarks, and a bench that builds only what it runs - #282
Merged
Conversation
…at builds only what it runs Measurement only; nothing behaves differently. Perf (HeedCore) puts os_signpost intervals, subsystem build.heed.app and category perf, around commit, rebuildList, readScreens, attentionEntries, AuditBrowser's refilter, DomainStore.flush, the telemetry cost recompute, and each wait in start() up to the cached domain being drawn. While nothing records, a signpost is one isEnabled check. AGENTS.md says how to record them with Instruments or xctrace. The Bench suite times SessionList and Attention on 50 sessions, 300 worktrees and 200 PRs, ScreenGuess on a 50x200 screen, ExternalText.display on a 20 KB body, a Prompt with ten fences, AuditBook with 50k actions and TurnEnd on a 4k-character line. Each prints its median and slowest; the ceilings are about ten times what each took, to catch a regression rather than a slow machine. mise run bench built the whole app in release, MLX included, and a release build of HeedCore alone did not finish in 30 minutes on a loaded machine. It now builds only the test product, as a debug build with -O (optimized, testable, compiled file by file), in its own scratch path so it and mise run test do not rebuild each other. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Mpdreamz
force-pushed
the
chore/signposts
branch
from
November 16, 2026 17:36
871f19a to
e7e28d0
Compare
Mpdreamz
added a commit
that referenced
this pull request
Nov 16, 2026
…s kept, text stripped once, the book read only for GitHub calls (#291) Part (c) of the code-health performance work: Audit, `ExternalText`, `Prompt.defuse` and the origin hook stop redoing work they had already done. The outputs are the same; only what gets recomputed changes. This PR merges on its own and does not touch the hook path, the sidebar, Attention, screen reading, startup, sync or telemetry. ## What changed - **Audit keeps its rows (finding 8).** `AuditBook` stores its rows. An action recorded is inserted by binary search, after equal ones, which is where the stable sort put it, and only its own row is built. All rows are rebuilt only when a cause that some chain reads changes, including a cause a chain stopped at because it was missing. `count(since:)` is a binary search and `outsideKeys` is stored. `==` and `hash` are still over the records only. `apply` now returns what changed. `AuditBrowser` uses it to insert a new row into the filtered list when `/` keeps it, and to recompute grant rows only when grants, revocations or their causes changed. The section toggle reads a stored `standingGrants` instead of calling `book.grantRows(before:)` in a view body. - **`ExternalText.display` is stored (finding 9).** It is stripped once in `init`, and shares the raw string's storage when stripping changes nothing. `==`, `hash(into:)` and the encoding are still over the raw text, source and author. - **`Prompt.defuse` uses a pattern compiled once** (finding 9). - **The origin hook checks the call's text before reading the book (finding 10).** `OriginNote.mayBringGitHub` returns false only when the parser could find nothing: - Bash: true when the command contains `gh` or `git` once quotes and backslashes are dropped. These are the only characters the tokenizer removes, so `'g'h` and `g\h` still pass, and every `github` URL contains `git`. - WebFetch: true when the URL contains `github` once percent escapes are decoded, case-insensitively, and always true for a URL with non-ASCII characters or escapes that do not decode. - **`OriginKeeper` writes in order and coalesces (finding 10).** Snapshots go through `submit` into a `Latest` slot, numbered on the main actor in the order they are taken. A single drain applies the newest one, and anything older than what was already applied is dropped. Before this, each snapshot went through its own `Task.detached`, so an older snapshot could overwrite a newer one. - **Checkouts capped (finding 10)** at `OriginBook.checkoutLimit = 500`, the size of the existing full-book fixture. Checkouts carry no date, so "oldest" cannot be known. The first ones listed are kept (repos, then worktrees) and the rest are dropped. - The `audit.refilter` signpost from #282 stays; `audit.follow` covers the incremental path. ## Benches (`mise run bench`) Run on origin/main (93a656c) with `AuditBench.swift` copied in, then on this branch. The machine had a load average of about 240 on 8 cores and the load varied between the two runs. The unchanged `branch name` bench took 1036 ms on main and 299 ms on the branch, so on the base run everything was roughly 3.5× slower. Read the ratios against that. | bench | main | this branch | |---|---|---| | audit record: one call into 5,000 actions, then rows + grant rows (`AuditBench`) | 145 ms | 0.074 ms | | origin note, `ls -la && swift build`, full book on disk (`AuditBench`) | 188 ms | 0.002 ms | | ExternalText.display, 20 KB × 100 (`CoreBench`) | 679 ms | 2.6 ms | | Prompt.text, 10 fences (`CoreBench`) | 0.325 ms | 0.131 ms | | AuditBook.apply + rows, 50k actions in one go (`CoreBench`) | 1190 ms | 321 ms (about the same after adjusting for load; the bulk path still sorts and builds every row) | | origin note, GitHub call (`HookBench`) | 133 ms | 44 ms (unchanged path; difference is load) | | branch name, 200k word (unchanged, load reference) | 1036 ms | 299 ms | ## Verification - New tests: - `AuditBookRowsTests` checks: - one action recorded builds one row (`rowsBuilt`); - rows recorded one at a time equal a stable sort of the records, including a same-time duplicate id; - a cause that arrives late rebuilds the rows, and an unrelated or identical cause builds none; - which changes flag grants; - equality and hash; - `count(since:)` against a linear count. - `ExternalTextTests` checks display, equality, hash and encoding. - `OriginNoteTests`: - `ls` and a non-GitHub URL read the book 0 times (also added to `theHookReadsTheBookOnceAndItStaysSmall`); - every command and URL in a set of 16 with a subject passes the text check; - the checkout cap; - the `Latest` slot; - an older snapshot never overwrites a newer one. - Mutation checks (each made to fail the new tests, then reverted): - stale-cause detection off; - `count(since:)` with `>`; - quote stripping removed from the text check; - URL check case-sensitive; - cap removed; - generation guard removed; - drain never ending; - `==` on display instead of raw; - always rebuild; - ties inserted before equal rows. This one at first passed: the duplicate was identical, and `whole` also took the insertion path. The test now compares against an explicit stable sort. - Full `mise run test` passed (2597 tests) on the branch rebased onto 93a656c. After the final rebase onto 661d7f4, the build and the touched suites (92 tests in 10 suites) passed; the full suite was not run again, as asked. `mise run lint` and `mise run text-check` passed before the final rebase. ## Not done or untested - `mise run tutor-check` was not run: it bundles the app, and the machine was too loaded. `AuditBrowser`'s incremental insert and cursor shift are app-layer code with no unit test. They reuse the tested `AuditBook.insertionIndex(of:in:)`. - `AuditView` still maps `rows.map(\.id)` for `ListBody` in its body; I left that alone. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Measurement only; nothing behaves differently. The numbers below are the "before" for the hook-path PR (code-health #11).
Signposts
Perf(HeedCore,Sources/HeedCore/Store/Perf.swift) adds os_signpost intervals, subsystembuild.heed.app, categoryperf. While nothing records, each one costs a singleisEnabledcheck.commitAppModel.commitrebuildListAppModel.rebuildListreadScreensattentionEntriesAppModel+Attention)audit.refilterAuditBrowser.refilterdomain.flushDomainStore.flush(encode and write)telemetry.costsstart.toCachestart()up to the cached domain being drawn, and inside itstart.callLog,start.detectTools,start.llm,start.telemetry,start.loadDomain,start.openLog,start.adopt,start.livePanes,start.replaceAGENTS.md has a new "Measuring the app" section on recording them: Instruments' Logging template, or
xcrun xctrace record --template 'Time Profiler' --instrument os_signpost --attach Heed …. I checked the template and instrument names againstxctrace list templatesandlist instruments. This Xcode has no template namedos_signpost.mise run benchThe old task ran
swift test -c release, which built the release app with MLX. A release build of the test product alone also failed: the whole-module optimized HeedCore compile was still running when it was killed at 30 minutes (load average about 150).The task now runs
swift build --scratch-path .build/bench -Xswiftc -O --product HeedPackageTests, thenswift test --skip-buildon the same scratch path:-O: optimized, testable, and compiled file by file instead of whole-module, so it builds in parallel and incrementally.mise run testandmise run benchfrom rebuilding each other's products.How the numbers relate to release: without whole-module optimization there is less inlining across files. The absolute times are therefore somewhat pessimistic compared with a release build, but the before/after comparison is valid as long as both sides run
mise run bench. The existingHookBenchorigin-note ceiling (median < 50 ms) was set on the old release build. On this machine, under load, it measured 50 ms in the first run and 290 ms in later runs, so it fails here. I left that ceiling unchanged.Build times, all with other builds competing for CPU:
.build.build/benchNumbers (before)
Median and slowest of each bench. Each run's load average is in its column header.
The ceilings in
CoreBenchare about ten times run 1's medians. They held in every run, including the one at load ~200.Checks
mise run fmtandmise run lint: clean.mise run test: 2551 tests passed. This also built HeedApp with the signposts in place.mise run bench: CoreBench passes. HookBench fails as described above.Not tested
🤖 Generated with Claude Code