perf(library): memoize scan parses per save (#143)
CI / ci (push) Canceled after 0s

Every FSEvents change — each 1 s autosave echo — ran Post.scan over the
whole library: read + frontmatter parse + title per post.md, O(library
bytes) per save cycle while writing, and the posts array was replaced
unconditionally, so every observing pane regrouped and re-rendered even
when nothing changed.

Post.scan now takes an optional PostScanCache (path+mtime+size-keyed
parse memo, nil default — every other caller unchanged): the readdir
walk stays the truth, only changed files are read and re-parsed. The
stamp is captured BEFORE the read and keys the store, so a mid-scan
rewrite can never be pinned as fresh — a late overlapping store keys
its own pre-read stamp and the next scan misses (review-caught race,
pinned by a same-size-rewrite test). rescan skips the posts assignment
when the scan equals the current list; @Observable invalidates on
assignment regardless of equality, so panes stop re-rendering on the
app's own autosave echoes.

Deliberately skipped (measured cold): folder(of:) caching (stat-only
walk) and refreshCards throttling (O(open piece), card surfacing
depends on it).

Closes #143
This commit is contained in:
AlexKucera committed 2026-11-03 11:19:50 +01:00
1 parent cc317b65b9
commit a2f6dc1653
9 files changed
+287 -39

No files matched your search

+4
View File
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format
## [Unreleased]
### Changed
- **library:** Incremental rescan (#143, OPT-F3) — every save/watcher cycle re-read and re-parsed EVERY post.md in the library (O(library bytes) per autosave echo, forever while writing) and replaced the posts array unconditionally, regrouping/re-rendering every observing pane even when nothing changed. `Post.scan` now takes an optional parse memo (`PostScanCache`, keyed on path+mtime+size — the readdir walk stays the truth, only changed files are read and re-parsed; the stamp is captured BEFORE the read so a mid-scan rewrite can never be pinned as fresh — an overlapping-rescan race the review caught, pinned), and the rescan skips the posts assignment when the scan equals the current list, so panes stop re-rendering on the app's own autosave echoes. Deliberately skipped (measured cold): `folder(of:)` caching (stat-only walk) and refreshCards throttling (O(open piece), card surfacing depends on it). Suite 573 (issue #143)
### Added
- **editor:** Drop an image into the prose (#141) — dragging an image file onto a saved post's prose editor COPIES it (never moves) into the piece's `assets/` under a parser-clean slugged name (collision `-2` via the shared uniqueFile helper) and inserts `![alt](assets/<slug>.<ext>)` at the drop point with `alt` selected for immediate type-over; one edit step = one undo. The type gate is exactly the publish rail's set (#34's `Micropub.mimeType` — PNG/JPEG/GIF/WebP/SVG: nothing enters `assets/` that can't ship), a Finder folder or a dropped SYMLINK refuses (`copyItem` would land the link itself and the publish rail would refuse the whole send), and drafts/outline/guest surfaces refuse loudly with a transient strip. Routing rides the window-level SwiftUI drop destination — field-verified to starve every deeper drag destination (nested SwiftUI targets never fire, AppKit NSDraggingDestination never fires) — pure-markdown sets keep the open-as-guest behavior, mixed md+image sets refuse loudly instead of silently dropping the images. The drop-point mapping inverts the one geometry source that answers under SwiftUI hosting (`firstRect`, bottom-up screen coords): a viewport-banded sample→bracket→binary-search over it — non-contiguous layout returns garbage rects for off-screen characters, so only in-band rects are trusted — then a whitespace-gap slide so a landing never splices inside a word or an existing ref; the solve is a pure function pinned by windowless tests, and the typewriter inset re-syncs after the edit so scrolling never freezes. Eleven tests incl. a flip-verified finish-audit cycle; suite 557 (issue #141)