Skip to content

Writing after a pause no longer waits on background work (#275) - #411

Merged
Joost-8 merged 6 commits into
mainfrom
fix-275-bookkeeping
Dec 3, 2026
Merged

Joost-8 merged 6 commits into
mainfrom
fix-275-bookkeeping

Conversation

@Joost-8

@Joost-8 Joost-8 commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Not verified on the device (the iPad bridge was in use by another session). Measured in the real-Obsidian rig with the CPU slowed. For Oskar: #275 is yours; Joost asked me to take this follow-up.

Follow-up to #275 (reporter, 3.0.0, iPadOS 17): strokes stop registering for a couple of seconds while the background work runs after a pause.

What changed

  • A page being read on the device stops when the pen lands. Grape's page read in the worker now yields between lines; the view aborts it on every pen down (readStop), the worker gets {cancel: id} and stops at the next line. A stopped read is rescheduled, and the page is not blamed (no skip, the client is kept).
  • A big notebook's first save no longer hashes the whole file in one block. The move to page files (Feature request: store each page in its own file (Obsidian Sync storage fills up) #274) is worked out at open, 64 KB at a time (payloadHashSteps, movedNotebookSteps); the first save uses it. The hash is unchanged (pinned against main's values), so two devices still make the same id.
  • Finding the next page to read hashes one page per slice (deviceStepSteps), given up when the pen lands.
  • Reviewer's findings, fixed: the search reads a copy of the pages (a page removed between two slices threw and left reading off until reopening); the read's stop is taken before the model loads; the move plan waits while the pen is down, with 16 KB chunks (~2 ms on an iPad). Cost: an unmoved big notebook spends ~0.5 s of background CPU after opening, in slices, even if not edited.
  • New pure model/steps.ts (finish, runSliced, 6 ms slices) and recognition/hwr/page-run.ts, both with tests.

Nothing visible changed, so there is no review page.

Proof

Rig (real Obsidian, CDP), write–pause–write bursts with a CPU profile:

Case Before (main) After
3.7 MB, 69-page notebook, CPU 6x: move hash at first save 854 ms in one block (payloadHash 519) gone
same: next-page search (pageContentHash of every page) ~240 ms in one block gone (a page per slice)
Reporter's practice sheet, one CPU core: Grape page read 9,403 ms, straight through the writing stopped 11–21 ms after each pen down
Strokes kept (practice sheet) 36 of 36 36 of 36

Tests: tests/view/device-reading-view.test.ts "stops the page being read when the pen lands, and blames no page (#275)" fails on main, and the two review tests ("…pen landed while the model loaded", "…a page is removed between two slices") fail on the first commit; tests/model/steps.test.ts pins the hash and the slicing; tests/recognition/hwr-page-run.test.ts. npm run gates: all 11 steps pass.

Test on the device

With Settings › Handwriting › Read on this device on:

  1. Open a big notebook still in the one-file form (a fresh copy of an old one, dozens of pages), write a line at once, rest 5 s, then write quickly: every stroke lands.
  2. On the reporter's practice sheet: write, pause 2–3 s, write again, several times: no gaps.
  3. Rest for half a minute: the transcripts still appear in the note.

iPadOS 18.2 and later deliver strokes late rather than losing them, so on a current iPad these steps may pass on main too: they check nothing broke. Only the reporter's iPadOS 17 shows the before.

Not verified

  • Not on the iPad. Chromium did not starve the main thread even on one core, so that the worker's read caused the reporter's gaps on WebKit is not proven; stopping it on pen down is the fix either way.
  • Still there: Obsidian's own hashing of a big file on every write (~200 ms at 6x), and a save at open (also on main). Not touched here.

🤖 Generated with Claude Code

Joost-8 and others added 6 commits December 3, 2026 01:20
- A page read on the device stops between two lines when the pen lands
  (the worker takes a cancel; the view aborts on pen down).
- The first save's move hash is worked out at open, a slice at a time.
- The search for the next page to read hashes a page per slice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…down

- The next-page search reads a copy of the pages (a page removed between
  two slices threw and left device reading off); deviceBusy is reset in
  a finally.
- The read's stop signal is taken before the model loads.
- The move plan waits while the pen is down; the hash yields every 16 KB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s growth

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Joost-8
Joost-8 marked this pull request as ready for review December 3, 2026 18:33
@Joost-8
Joost-8 merged commit ab3d074 into main Dec 3, 2026
1 check passed
@Joost-8
Joost-8 deleted the fix-275-bookkeeping branch December 3, 2026 18:33
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