Repository navigation
perf: 1 read for a push batch's answers, and link views read again once saves stop - #239
Merged
Merged
Conversation
… write lock log.push read each item's earlier answer in a write transaction of its own, so a batch of 100 items took the database's write mutex 100 times and could hold up every vault writer on the hub. store.DB.PushAnswers reads the whole batch's answers in 1 query outside DB.Tx; the per-vault log lock already keeps other pushes of the vault out. A refusal recorded for missing content stays visible to a repeat later in the same batch. Fixes #210
The Backlinks and Outgoing links panes and the status bar's backlink count read notesd again on every change to the files store, so each autosave cost note.backlinks twice, note.read, note.search and note.links, even when no link changed. useLinksVersion goes up at once when the set of paths changes, and otherwise 2 s (twice the editor's save delay) after the files last changed, so a burst of saves costs 1 read. Fixes #212
Contributor
Author
|
Revert test at head 41482c6, in a scratch worktree (
At the head, both pass. The scratch worktree is removed. |
Contributor
Author
|
Cross-review (initial review, 1 of the budget): Ready, Blocking: none, no findings.
|
bketelsen
approved these changes
Nov 14, 2026
Contributor
Author
|
Full seeded sync simulation at this head: PASS.
The seconds per seed are longer than plan 0004's record (7 to 10 min stepwise, about 80 to 90 s concurrent). This run was 1 process on a shared 8-core VM, and the record does not name its machine, so the times are not a like-for-like comparison. |
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.
Summary
Two small performance fixes from a code review of
main, each in its own commit.Hub: 1 read for a push batch's earlier answers (Fixes #210).
log.pushread each item's earlier answer in a write transaction of its own (answered→DB.Tx→tx.PushAnswer), so a batch of 100 items took the database's write mutex 100 times and could hold up every vault writer on the hub. The newstore.DB.PushAnswersreads the whole batch's answers in 1 query (push_id IN json_each(?)) outsideDB.Tx. The per-vault log lock already keeps other pushes of the vault out, and onlylog.pushrecordshub_pushesrows, so the read sees every answer a write transaction would. The answers the device gets stay the same; a refusal recorded for missing content is put in the batch's map, so a repeat of that push later in the same batch still gets it, as before.Web app: link views read again once the saves stop (Fixes #212). The Backlinks and Outgoing links panes and the status bar's backlink count had the files map as their trigger, so each autosave cost 2
note.backlinks, anote.read, 1 or morenote.searchand anote.links, even when no link changed.useLinksVersion(app/src/app/vaultChanges.ts) is their new trigger: it goes up at once when the set of paths changes (pathsVersion: a file added, moved or removed, or a new listing), and otherwiseLINKS_DELAYafter the files last changed.LINKS_DELAYis 2 s, twice the editor'sSAVE_DELAY: saves are at least 1 s apart, so a delay likeCOUNT_DELAY(150 ms) would merge none of the saves of a person typing. The panes now catch up about 2 s after the last save.docs/design/app.mdsays so.Risk tier
Risk tier: 2 — a behavior change in code (when the hub reads push answers; when the web app's link views refresh). No path in
.github/risk-paths.jsonis touched (internal/hub/log.gois not ininternal/hub/{hub,pair,withdraw,relocate}.go).Docs housekeeping
docs/design/app.mdupdated for the link views' refresh; no new doc, ADR or spec change (the sync protocol's answers are unchanged).Verification
make cigreen (host and nsl: verify,ui-checkwith 819 tests,desktop-build, race tests)make ui-checkgreen (nsl), for a change underapp/make sync-sim, for a change to sync, at head 41482c6: stepwise seeds 1–4 (10,000 steps each) passed, thenSIM_MODE=concurrent SIM_SEEDS=3 make sync-simpassed (TestISimulationandTestRegressions). The full default run (10 seeds in each mode) was not run.internal/hub/log.go,app/src/app/status.tsandapp/src/app/panes/links.tsxreverted:TestARepeatedBatchDoesNotWaitForTheWriteLockfails ("waited for the database's write lock") and the panes test fails (expected 8 to be 2); details in a comment.openai/gpt-6.1-sol, Ready, no findings (comment).New targeted tests:
internal/hub:TestARepeatedBatchDoesNotWaitForTheWriteLockholds the write lock in aDB.Txand pushes a batch of 3 repeated items; it fails if the batch waits for the lock, and checks that the answers equal the first ones.internal/store:TestReplicasAndPushAnswerscoversPushAnswers(another replica's answers left out, repeats, no pushes), read while a write transaction is open.app/src/app/vaultChanges.test.ts: the hook goes up once after a burst of saves, and at once for an added, moved or removed file.app/src/app/panes.test.tsx: "read a note's backlinks again once the vault's saves stop, not at each save": 3 saves cost no read until they stop, then 1 for the pane and 1 for the status bar.