Repository navigation
Audit, other people's text and the origin hook stop redoing work: rows kept, text stripped once, the book read only for GitHub calls - #291
Merged
Conversation
…s kept, text stripped once, the book read only for GitHub calls Each path did the same work again on every call or redraw. The outputs are the same; only what is recomputed changes. - **Audit keeps its rows.** `AuditBook` stores its rows next to the actions. An action recorded is inserted at its place by binary search (after equal ones, as the stable sort put it) and builds only its own row. The rows are built again only when a cause that a row's or a grant's chain reads changes, including a cause that a chain stopped at for want of it. `count(since:)` is a binary search and `outsideKeys` is kept. Equality and hashing stay over the records. `apply` says what changed, and `AuditBrowser` inserts a new row into the filtered list when `/` keeps it, instead of filtering every row again. It recomputes grant rows only when a grant, a revocation or a cause they read changed. The section toggle reads a stored count of standing grants instead of building grant rows in the view body. - **`ExternalText.display` is stored.** It is stripped once in `init` and shares the raw string's storage when stripping changes nothing. `==`, `hash(into:)` and the encoding stay those of the text as written. - **`Prompt.defuse` compiles its pattern once**, not once per fence. - **The origin hook reads the book only for calls that may be about GitHub.** `OriginNote.mayBringGitHub` checks a Bash command for `gh` or `git` once quotes and backslashes are dropped (so `'g'h` and `g\h` still count), and a WebFetch URL for `github` once percent escapes are decoded. Any non-ASCII URL counts as a GitHub URL. The check is conservative: a call the parser would report always passes it. `ls` reads the book 0 times. - **The origin book's writes are ordered and coalesced.** `OriginKeeper` used to get each snapshot through its own detached task, so an older snapshot could land after a newer one. Snapshots are now `submit`ted into a `Latest` slot, numbered in the order the main actor takes them. One drain applies the newest. A snapshot older than the one applied is dropped. - **Checkouts are capped** at `OriginBook.checkoutLimit` (500). The first ones listed are kept: repos, then worktrees. Tests: `AuditBookRowsTests` (rows built one at a time, rows recorded one by one against a stable sort including a same-time duplicate, a late cause rebuilding, grant changes, equality and hash). Also added: a display/equality/encoding test in `ExternalTextTests`, and prefilter, cap, `Latest` and keeper-ordering tests in `OriginNoteTests`. `theHookReadsTheBookOnceAndItStaysSmall` now also checks that `ls` reads the book 0 times. Benches: `AuditBench` (one call recorded into 5,000 actions; a non-GitHub hook call with a full book), next to `CoreBench`'s. 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.
Part (c) of the code-health performance work: Audit,
ExternalText,Prompt.defuseand 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
AuditBookstores 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 andoutsideKeysis stored.==andhashare still over the records only.applynow returns what changed.AuditBrowseruses 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 storedstandingGrantsinstead of callingbook.grantRows(before:)in a view body.ExternalText.displayis stored (finding 9). It is stripped once ininit, 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.defuseuses a pattern compiled once (finding 9).OriginNote.mayBringGitHubreturns false only when the parser could find nothing:ghorgitonce quotes and backslashes are dropped. These are the only characters the tokenizer removes, so'g'handg\hstill pass, and everygithubURL containsgit.githubonce percent escapes are decoded, case-insensitively, and always true for a URL with non-ASCII characters or escapes that do not decode.OriginKeeperwrites in order and coalesces (finding 10). Snapshots go throughsubmitinto aLatestslot, 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 ownTask.detached, so an older snapshot could overwrite a newer one.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.audit.refiltersignpost from Signposts on the app's hot paths, HeedCore benchmarks, and a bench that builds only what it runs #282 stays;audit.followcovers the incremental path.Benches (
mise run bench)Run on origin/main (93a656c) with
AuditBench.swiftcopied 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 unchangedbranch namebench 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.AuditBench)ls -la && swift build, full book on disk (AuditBench)CoreBench)CoreBench)CoreBench)HookBench)Verification
AuditBookRowsTestschecks:rowsBuilt);count(since:)against a linear count.ExternalTextTestschecks display, equality, hash and encoding.OriginNoteTests:lsand a non-GitHub URL read the book 0 times (also added totheHookReadsTheBookOnceAndItStaysSmall);Latestslot;count(since:)with>;==on display instead of raw;wholealso took the insertion path. The test now compares against an explicit stable sort.mise run testpassed (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 lintandmise run text-checkpassed before the final rebase.Not done or untested
mise run tutor-checkwas 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 testedAuditBook.insertionIndex(of:in:).AuditViewstill mapsrows.map(\.id)forListBodyin its body; I left that alone.🤖 Generated with Claude Code