Skip to content

Signposts on the app's hot paths, HeedCore benchmarks, and a bench that builds only what it runs - #282

Merged
Mpdreamz merged 1 commit into
mainfrom
chore/signposts
Nov 16, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
chore/signposts

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

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, subsystem build.heed.app, category perf. While nothing records, each one costs a single isEnabled check.

Interval Where
commit AppModel.commit
rebuildList AppModel.rebuildList
readScreens the screen-reading tick, including its detached guess
attentionEntries the Attention feed and ranking (AppModel+Attention)
audit.refilter AuditBrowser.refilter
domain.flush DomainStore.flush (encode and write)
telemetry.costs the detached telemetry cost recompute
start.toCache start() up to the cached domain being drawn, and inside it start.callLog, start.detectTools, start.llm, start.telemetry, start.loadDomain, start.openLog, start.adopt, start.livePanes, start.replace

AGENTS.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 against xctrace list templates and list instruments. This Xcode has no template named os_signpost.

mise run bench

The 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, then swift test --skip-build on the same scratch path:

  • It builds HeedCore and its tests only. No HeedApp, no MLX, no Sparkle.
  • It is a debug build with -O: optimized, testable, and compiled file by file instead of whole-module, so it builds in parallel and incrementally.
  • Its own scratch path keeps mise run test and mise run bench from 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 existing HookBench origin-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 Load average Time
Cold, default .build ~120–160 1333 s
Cold, .build/bench ~200–225 2500 s
Warm, no change ~175 10 s

Numbers (before)

Median and slowest of each bench. Each run's load average is in its column header.

Bench Run 1 (load ~159) Run 2 (load ~175)
SessionList, 50 sessions × 300 worktrees, with the app's size and Can close closures 2.7 ms / 48 ms 3.8 ms / 108 ms
AttentionFeed.items + AttentionRanking.entries, 200 PRs 7.5 ms / 44 ms 36 ms / 266 ms
ScreenGuess.guess, 50×200 screen 0.33 ms / 43 ms 0.62 ms / 62 ms
ExternalText.display, 20 KB × 100 305 ms / 421 ms 1144 ms / 1503 ms
Prompt.text, 10 fences 0.35 ms / 38 ms 0.67 ms / 83 ms
AuditBook.apply + rows, 50k actions 560 ms / 682 ms 1755 ms / 2197 ms
TurnEnd.asksYou, one 4k-char line 1.06 ms / 54 ms 6.8 ms / 198 ms
OriginNote.report (HookBench) 50 ms / 87 ms 290 ms / 554 ms

The ceilings in CoreBench are about ten times run 1's medians. They held in every run, including the one at load ~200.

Checks

  • mise run fmt and mise 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

  • I did not record a trace of the running app, so the signposts have not been seen in Instruments. Recording through xctrace can raise a macOS developer-tools permission prompt.
  • I did not get a quiet-machine run.

🤖 Generated with Claude Code

…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
Mpdreamz merged commit 1d0f141 into main Nov 16, 2026
3 checks passed
@Mpdreamz
Mpdreamz deleted the chore/signposts branch November 16, 2026 17:51
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]>
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