oficina / docs Public

S1b: incremental pagination and lazy layout (native redesign); typing-lag step 0; iPhone plan needs a ruling open

On branch perf/native-s1b

S1b of the Docs native redesign: incremental pagination and lazy layout (Mac), and step 0 of the typing-lag report. Spec docs/superpowers/specs/2026-11-22-native-redesign-design.md §7 (Incremental pagination, iPhone layout, Fallback, Measurement), §11; plan S1b; Fable's #157 r2/r3. On main 93230c0. Not merged, released or deployed. No visible change: every snapshot is pixel-identical.

One part stops and reports: the iPhone. The spec's iPhone plan cannot hold with UIKit's TextKit 1 (details below). The Mac part is done; iPhone layout is unchanged on this branch and needs a ruling.

Commits

  • facc40e step 0: probes for the whole keystroke path (line requests counted inside the containers, pagination, the text view's layout and drawing, toolbar refresh, command; the UI probe's "keyDown to drawn" and display-pass timings)
  • 89c8f55 incremental pagination on the Mac (DocsPagination); today's measurement moves to the tests as DocumentPageLayoutOracle
  • 5fd2369 pagination equivalence, large-document and line-request tests
  • 385198d keep typing out of the window's SwiftUI views (step 0's non-pagination finding)
  • 6c7eab5 iPhone keystroke and large-document probes (env-gated)
  • 3a9fc13 the numbers (native/benchmarks/README.md)

Step 0: the cause, confirmed

Mac UI probe (real DocsWorkspace window, Release + DOCS_PROBES, 40 keys at 8/s), main + probes, load 130–240:

| keyDown / keyDown→drawn | p1 | p5 | p20 | p50 | p200h | |---|---|---|---|---|---| | paged | 3.7 / 6.8 ms | 17.7 / 21.2 | 65.6 / 68.9 | 179 / 182 | 716 / 720 | | pageless | 1.3 / 4.5 | 1.3 / 4.6 | 1.5 / 4.7 | 2.1 / 5.5 | 6.9 / 10.3 |

  • Paged: pagination, as suspected, and all of it. Per key at p20, two updatePagination passes (copy + whole layout of the copy) 36 ms, and layout()'s whole-container ensureLayout 29 ms; 759 line requests to each of the live and measurement containers (7,694 at p200h).
  • Pageless: layout()'s whole-container ensureLayout, 6–9 ms a key at p200h.
  • Outside pagination, > 2 ms a key (fixed in 385198d): the display pass after every key spent 3.1–4.1 ms in NSHostingView.layout (sampled): SwiftUI re-evaluated the workspace (its body read outboxSummary for the offline banner and the lost-changes alert: moves twice a key), the Format inspector, the iPhone toolbar and the Format menu (they read DocumentCommands.isEnabled, false while input is pending), and on iPhone the sync row and the library's Accounts/Sign out (syncStatus, hasUnsavedChanges). The RenderIsolation test counted 88 workspace bodies over 40 keys. Now each is read in its own small view, the panels/menu read isAvailable and each command checks isEnabled as it runs (it already did); display pass 3.2 → 0.05 ms. Gate: RenderIsolationTests holds workspace + inspector bodies at 0 per key after the first (Mac and iPhone).
  • The inspector refresh S1a added on every draw: refreshToolbarSelection runs 5× a key; each walked the whole projection 4× (allocating a path per node) and decoded the marks JSON once per mark asked: 0.09 ms at p20, 0.5 ms at p200h (2.4 ms a key). Now marks are read once and the path is searched in the selection's top-level block only: 0.01–0.04 ms a refresh.
  • Drawing, p200h paged: NSTextView passes its whole bounds to drawBackground; all 215 page labels were string-drawn every frame. Now only those in the clip.
  • Under 2 ms, reported not fixed: SLSObscureCursor (AppKit hiding the cursor on keyDown, a WindowServer round trip; about a third of keyDown samples under this load; the system's), enqueue re-encoding the pending queue as JSON for its 2 MB check (0.1–0.25 ms), spell checking's NSTextCheckingController (~0.1 ms).
  • iPhone (simulator): per-key median 1.3–4.5 ms, but max 5.8 ms (p1) → 1,123 ms (p200h paged), with line requests = the whole document (59 → 10,454): see the iPhone section.

What the Mac does now (§7 Incremental pagination)

  • Measurement stack on the same storage (1): a second DocsLayoutManager attached to the live NSTextStorage, with DocsMeasureTextContainer, a simple rectangle as wide as the paper's text. No copy, no measurementContent. Non-contiguous, background layout off.
  • Per-block caches (2): one unit per .docsTopBlock run that starts a paragraph: advance (first line top → last line fragment bottom), usedBottom, both margins; natural tops are prefix sums; edits are splices (Return grows a unit; delete, paste, multi-dirty flushes re-read only the touched units and their neighbours; units the edit didn't touch keep their numbers).
  • Full path (3): at open (to the visible bottom at once, then 50 units a run-loop turn), on a text-width change, when more than 50 units changed at once; a scroll or scrollRangeToVisible past the frontier measures up to it first (viewWillDraw, scrollRangeToVisible). Zoom never runs it. Without a window (tests, snapshots) it all runs at once.
  • Per edit (4): re-measure the dirty units; today's break algorithm from the last break before the first dirty unit, stopping at a break past the last dirty unit with the same extra. Runs from the text view's layout() (once per turn, before display; didChangeText lays out first, as before).
  • Break table and lookup (5): per unit (breaks by block id for tests). The live container asks for a break's absolute top topU + X and takes max(proposed, top).
  • Invalidation (6): never textContainerChangedGeometry; invalidateLayout(forCharacterRange:) on the live manager from the first unit whose top moved; the visible rect redisplayed only if something moved.
  • Frame height (7) from the caches; layout() (8) no longer lays out the whole container.
  • Oracle (9): DocumentPageLayoutOracle in the test target, verbatim.

Where the implementation differs from the spec's words (please check)

  1. The measurement container is not plain. A plain NSTextContainer loses the live container's code padding (a line starting with inline code is narrower), which changes wrapping, so its geometry would not be "exactly the natural one". DocsMeasureTextContainer keeps that one width rule and reports itself a simple rectangle (it never moves lines vertically; the top margin and docsFirstMargin are applied to unit 0's cached top instead). This matters: with today's non-rectangular DocsPageTextContainer as the measurement container, TextKit lays it out contiguously; a far edit after a near one re-laid out 8,515 lines (575 ms). With the rectangle, far and near edits cost microseconds.
  2. The Mac's live layout ships on the §7 fallback (contiguous, to the visible bottom). TextKit does not lay out a non-rectangular container non-contiguously (iOS bare-stack experiment below; on the Mac, Pages toggled at the end of p200 re-lays out from the first break to the end). So allowsNonContiguousLayout = false and background layout off on the live manager: layout goes to the visible bottom, a jump costs O(position) once, never per key. The lookup is for breaks only, max(proposed, top), exactly item 5.
  3. Caches are kept in pageless too. Item 7/8 (height from the caches, no whole-container layout in layout()) apply to both modes, so the stack runs in both; turning Pages on is then the break pass plus invalidation, not a re-measure.
  4. Frame height uses the last line fragment's bottom (what layout() read from the last glyph), not usedBottom(last) as item 7's formula says: they differ by the last paragraph's spacing, and the snapshots must stay identical.
  5. A break never goes inside a paragraph. Per §7 D4 a unit is a paragraph-starting run plus any runs after it that don't start one. After a Backspace at a block's start the oracle (measuring runs) can break inside the merged paragraph; production doesn't. testNoBreakInsideAMergedParagraph shows the oracle doing it and production not. Only this transient state differs.
  6. Pagination lives with the text view (DocsPagedTextView.pagination, its unit index kept from the live layout manager's processEditing), not in DocumentSurface: the surface's block index is unchanged, and text views without a surface (tests, the oracle comparisons) paginate the same way.

The iPhone: the spec's plan does not hold (stopped; needs a ruling)

PhoneLargeDocumentTests (env-gated probe) on 200 pages paged, simulator:

  • Opening lays the whole document out: 21,808 line requests, 1.5 s; nothing is left unlaid.
  • A key that makes a new line: 12,349 line requests, 0.47 s; plain keys 4–6.
  • Not our ensureLayout: removing it and switching to non-contiguous layout changed nothing. A bare stack (storage + NSLayoutManager + DocsPageTextContainer, no view): setting the document = 12,346 requests, 0.72 s; one new line near the start = 12,347, 0.71 s, contiguous or not. The trace is -[NSLayoutManager _markSelfAsDirtyForBackgroundLayout:] → _fillLayoutHoleAtIndex:desiredNumberOfLines: inside the storage edit: TextKit 1's background layout, which on iOS runs synchronously and fills to the end, and which cannot shift the rest for a non-rectangular container.
  • With backgroundLayoutEnabled off (a property that exists on iOS's NSLayoutManager but is not in the iOS SDK headers, set by KVC): the same bare stack costs 0 requests to set the document, 49 for the first screen, 0 for the new line, 39 to lay the screen out again. Setting it on the text view's own manager ended the test process; not investigated further.
  • Also seen (on main's iOS code, unverified): at the end of p200h the UITextView caret rect is 72.7 pt above its glyph's line.

Options: (a) the non-public property (App Review risk; needs work on the crash); (b) a rectangular container on iOS with page geometry done differently (a design change, and pixels); (c) TextKit 2 for the iPhone text view (larger); (d) leave iOS as is for now. The fallback "contiguous to the visible bottom" is not available on iOS either: TextKit lays out to the end itself. Not changed on this branch.

Hard gates

  • Line-fragment requests per key (TextKit's, counted inside our container), through the key's display: testLineFragmentRequestsPerKey, p20 and p200, paged and pageless, 40 keys: 2 per key, 19–28 on the key that wraps (bound: edited block's lines + visible lines + 8 = 42–44). UI probe: 759 → 6 at p20, 7,694 → 6 (max 21) at p200h. Layout invalidated beyond the edited block when no height changed: none (6 requests = the edited paragraph's lines).
  • keyDown, paged, p20: median 2.4 ms (target ≤ 5); 200 keys median 1.8, p95 2.4 ms (≤ 10). p200h 3.4 ms (≤ 8).
  • Stalls > 16.7 ms while typing, p20 paged: 40 → 0 (all three runs); p200h paged: 0.
  • S1a's counters unchanged (whole renders 0, host bodies 0, 1 block render a key, iOS attributedText 0).

Numbers (A = main + probes facc40e, B = branch; p20/p200h medians of 3 interleaved; load 150–600)

| | p1 | p5 | p20 | p50 | p200h | |---|---|---|---|---|---| | keyDown, paged | 3.7 → 1.9 ms | 17.7 → 2.1 | 66.3 → 2.4 | 179 → 2.4 | 680 → 3.4 | | keyDown → drawn, paged | 6.8 → 2.0 | 21.2 → 2.1 | 69.5 → 2.5 | 182 → 2.5 | 683 → 3.5 | | keyDown, pageless | 1.3 → 1.4 | 1.3 → 2.1 | 1.7 → 2.6 | 2.1 → 3.9 | 8.7 → 2.6 | | keyDown → drawn, pageless | 4.5 → 1.4 | 4.6 → 2.1 | 4.8 → 2.7 | 5.5 → 3.9 | 12.1 → 2.7 | | stalls > 16.7 ms, paged | 0 → 0 | 40 → 0 | 40 → 0 | 7 s block → 0 | 27 s block → 0 |

Pageless keyDown is up 0.1–0.9 ms at p5–p50 (single runs, noisy; the measurement stack costs ~0.4 ms a key) but keyDown → drawn is down everywhere (the display pass). Peer change, all main-thread busy, paged: p20 94 → 32 ms, p200h 315 → 39 ms. Pages off/on at the end of 200 pages: 0.50–0.63 s at load 450–600 (contiguous relayout of 8,500 lines from the first break), above the ≤ 250 ms target; at the top it is cheap. iPhone unchanged: per-key median 1.3–2.7 ms, max 4 ms (p1) to 250–440 ms (p200h); open p200h 0.6 s.

Tests

  • PaginationEquivalenceTests (§11): typed through the real DocsTextView, checked before and after publication: typing before a break, optimistic Return, Backspace at a block's start, a block deleted, three blocks pasted, three blocks in one flush, typing inside a list taller than a page, typing that moves a break and back; without a window and in one at 100% and 150%. Fixture: a large heading and an image first after a break, inline code starting lines, a code block. Breaks, every line origin (0.5 pt) and frame height equal a fresh oracle run. Seen to fail with breaks kept by character index (line origins off by 126–168 pt) and with the break's offset applied relatively (off by thousands of points).
  • PaginationLargeDocumentTests (§7 item 10, 200 pages, Mac): after the idle chunks the live manager has no layout at the end; ⌘↓ and type: caret against glyph, no line across a separator, pages equal the oracle's, caret line where a whole layout puts it; the same with the jump before the chunks finish; again after Pages off and on.
  • RenderIsolationTests: + workspace/inspector bodies per key (88 before).
  • swift test: 243 tests (+14 swift-testing), 0 failures, 12 skipped (env-gated probes, snapshot gates). test-iphone.sh: 20 tests, 0 failures, 3 skipped (probes). EditorRenderLoopTests green on both.
  • No observed state is mutated in an init or body (the new views only read).

native/scripts/snapshots.sh compare all

Test Case '-[DocsSnapshots.DocsEditorSnapshots testEditorScreens]' passed (12.745 seconds).
Test Case '-[DocsSnapshots.DocsSnapshots testKeyScreens]' passed (9.311 seconds).
Test Case '-[DocsSnapshots.DocsWindowSnapshots testWindowScreens]' passed (12.519 seconds).
docs-editor snapshots (compare, 24 images)
docs snapshots (compare, 22 images)
docs-window snapshots (compare, 22 images)
mac half drawn on: macOS 27.0.0, Xcode 27.2 (27B52); docs, docs-editor, docs-window: baselines drawn on the same
docs-editor snapshots (compare, 20 images)
docs-editor-ax3 snapshots (compare, 4 images)
Test Case '-[DocsPhoneSnapshots.DocsEditorSnapshots testEditorScreens]' passed (9.189 seconds).
docs snapshots (compare, 32 images)
Test Case '-[DocsPhoneSnapshots.DocsSnapshots testKeyScreens]' passed (10.542 seconds).
iphone half drawn on: iOS 27.0.0, runtime 27.0 (24A434); docs, docs-editor, docs-editor-ax3: baselines drawn on the same
exit 0

(Two earlier runs at load 450–600 reported a few screens "still changing after 3.0 seconds": the opening counter outlived the kit's 3 s limit under load; idle checked separately: zero layouts, paginations or draws in a second.)

Other gates

  • check-native.sh --mutations: passed, 20 mutations caught; its swift test 243 tests, 0 failures.
  • Mac release build (build-mac.sh): exit 0 (native/build/Oficina Docs.app).
  • test-document-window.py, plain and with the 60-paragraph caret_fixture: PASS both (caret against glyph, Enter/typing caret stable). The composition-before-separator regression (testOptimisticAndMarkedEditsInvalidatePageOffsets, ja marked text before a break) passes.
  • Hub CI at 3a9fc13: CI passed (amadan ci status oficina/docs -branch perf/native-s1b).
  • Not run here: copy review (no new strings), the physical-device pass (before release), test-home-loading.py / test-offline-kill.py / test-sync-latency.py.

Applied the coordinator's ruling on the iPhone question: (d), no private API. Commit b868095 (spec and plan only; pushed; no code change).

  • Spec §7 "iPhone layout": records the finding (TextKit 1 lays out the rest of the document inside any edit that changes a line count; it lays out all of it at open; the §7 fallback isn't available on iOS either), that backgroundLayoutEnabled (private API, and it crashed the test) is not used, and the ruling: iPhone pagination stays as it is for S1b, and S3 rebuilds the iPhone editor on TextKit 2.
  • S3's acceptance (plan) carries the p200h targets, paged, in the simulator: - per key ≤ 8 ms median, and no stall over 16.7 ms on a key that changes a line count (today 250–500 ms); - open lays out no further than the visible bottom, ≤ 250 ms to the first screen (today 0.6–1.5 s); - the §7 iPhone jump-to-end check.

New S3 work item 6a: TextKit 2, and investigate the possible 72.7 pt end-of-document caret offset (noted, not fixed).

  • Known gap, in the spec's new "S1b amendments" table and the plan's S1b section: Pages off/on at the end of 200 pages takes 0.50–0.63 s (load 450–600) against the 250 ms bound, because the Mac's live layout is contiguous (§7 fallback). At the top of a document the toggle is cheap.
  • Plan S1b: work item 5 and the iPhone p200h check are withdrawn from S1b.

Branch now b868095. Ready for Fable's review; not merged.

Whole-branch review of perf/native-s1b — Claude Fable (model claude-fable-5-2), review-only worktree at 3a9fc13, since removed. b868095 (spec/plan amendments) read: docs only.

Verdict: APPROVE AFTER FIXES

One small fix (finding 1). The rest are low or notes. The pagination itself I could not break.

What I ran

  • swift test at 3a9fc13 (after build-crdt.sh): 243 tests, 0 failures, 12 skipped, incl. PaginationEquivalenceTests, PaginationLargeDocumentTests, RenderIsolationTests. Machine load was ~520 throughout, so my timings below are inflated.
  • A review-only seeded fuzz against the oracle (not committed): a bare DocsPagedTextView on the equivalence fixture, random storage edits (single characters, wrapping inserts, Return inside a block, whole-block delete, in-paragraph delete, paste of 1–4 rendered blocks incl. headings, block replaced by another kind, two distant edits in one beginEditing, newline delete then a later "publication" of the merged paragraph, Pages toggle, scrollRangeToVisible, single idle chunks, and a forced full re-read). Breaks, separators, every line origin (0.5 pt) and frame height compared with a fresh oracle run (paged) or a plain whole layout (pageless). - No window: 8 seeds × 400 ops, then 3 × 400 with resets/merges. In a window at 4/3: 16 seeds × 400, then 12 × 500 with resets/merges; 348 comparisons in that last set, 263 of them with measuring incomplete when the comparison started. - 0 mismatches. The live layout manager's layout persisted across edits between comparisons, so a missed invalidation would have shown as a stale line origin. - Not covered by it: the transient break-inside-a-merged-paragraph state (comparison skipped while a run starts mid-paragraph, deviation 5), 150% zoom, IME, images with real sizes.

Findings

  1. Medium-low — leaving the window mid-measure measures the whole rest in one turn. DocsPagination.swift:463-476 (the chunk timer) with :305-319 (canDefer() false ⇒ the frontier loop never breaks). Reproduced: 400 pages in a window, window.contentView = nil with the frontier at 6 of 2,280 units; the pending timer then measured the other 2,274 in a single 1.7 s main-thread turn (load ~520). In the app this needs the text view to outlive its removal by one run-loop turn (editor → home shortly after opening a big document); I did not verify that in the real window. Fix: the timer returns unless canDefer(), and measuring resumes from the next layout() in a window. Add the test.
  1. Low — idle chunks are a fixed 50 units, back to back, each with a redisplay. DocsPagination.swift:133, 463-476; finish() :403-410; paginationChanged DocsPagedTextView.swift:82-86. At 200 pages (1,140 units, 23 chunks) measuring alone took 31 ms median, 45 ms max a chunk at load ~520; in a window the worst turn was 76 ms. Every chunk also sets needsLayout and redisplays the visible rect, because moved is true whenever the estimated bottom or a far separator changes. This conforms to the spec (50 a turn) and is far better than main; typing in the first second after opening a large document will still see these. Suggest a time box per turn and no redisplay when nothing at or above the visible bottom moved. #173 has no Mac open or typing-during-open number; one line would settle it.
  1. Low (tests) — no gate covers edits while measuring is incomplete. PaginationEquivalenceTests.swift:91-99: production() calls update(visibleBottom: .greatestFiniteMagnitude), so after the first assertion every edit runs with the frontier complete. The large-document tests check the caret's line and counts only. Also ungated: the more-than-50-stale path (DocsPagination.swift:301-304), pageless line origins, two edits in one editing group, mixed sequences. All passed in my fuzz; a small seeded version of it (a few seconds) would hold them.
  1. Note — the .allowsHitTesting(actions.isEnabled) removal (DocsFormatInspector.swift:83-86, EditorToolbar.swift:58-62): a click while input is pending used to fall through the panel (on the Mac, to the text under the floating inspector); now the control takes it and the command refuses silently. Every entry point checks isEnabled (DocumentCommands.swift:37, 68, 80, 110). Arguably better; just a behaviour change to know about.
  1. Note — memory. 200 pages (725k characters): the first complete layout of either manager costs about 180 MB of footprint (62 → 242 MB); the second manager's complete layout adds 5–15 MB. So the measuring stack's marginal cost is small, and main already paid the large part (whole live layout plus a copy per key). Keeping the stack in pageless (deviation 3) costs the same.

Checked and found sound

  • Equivalence with the oracle. The break pass is the oracle's recurrence over advance/usedBottom/margins. Prefix sums are valid because line rects tile vertically in both containers and a unit is whole paragraphs. Stopping at a break past through with the same extra is sound: everything after a break depends only on that break's unit and later, unchanged, measurements. after read at the unit's last character equals the oracle's read at its first for a single-id unit (NativeTextProjection.swift:68 sets it over the block).
  • The measuring container's shape. Line width is textWidth in both (DocsPageGeometry.lineRect), the code-start rule is the same, the line-height delegate is the same class, attachment bounds are fixed (DocsAttachments.swift:120-145) and independent of the container. The live container's only vertical rules on the Mac are the 72 pt top, docsFirstMargin and the breaks, all applied to the caches. No line can differ in height or wrap.
  • Staleness. Every layout input reaches the caches as a storage edit (image arrival and fonts re-render blocks; margin collapse rewrites neighbours' attributes). Zoom is scroll-view magnification only. A stale top between the edit and layout() is corrected by the invalidation from the first moved unit. Peer edits and idle chunks are both main-actor and go through the same storageEdited/update.
  • Deviations 1–6: accepted. 5 matches the spec's own sentence in §7 Design 4 ("allows a break only where a run starts a paragraph").
  • 385198d. DocsModel is @Observable, so the three small views track what they read; nothing mutates observed state in an init or body (only probe counters). The lost-changes alert moved onto NativeOfflineBanner, whose body is an empty Group when online: I checked in a scratch SwiftUI app on macOS 27 that an alert attached to such a view inside safeAreaInset still presents (it does, banner shown or not). Not checked on iOS. activeMarks and the top-block-first path(to:) return what the old code did (fallback to the whole search is kept).
  • Pages toggle at the end of 200 pages: the known gap, as recorded in b868095.

Not run by me: the UI probe, test-document-window.py, snapshots, anything on iPhone.

Fable's review (APPROVE AFTER FIXES): all four addressed. Branch at 0584b48; separate commits, each with a test that fails without it (mutations noted). Not merged.

  1. f716af1 Leaving the window mid-measure. The pending idle chunk returns unless canDefer(); the next layout in a window schedules measuring again. Test testLeavingTheWindowMidMeasureMeasuresNothingMore: 400 pages, the view taken out of its window mid-measure, nothing measured for 300 ms, then put back in a window and measured to completion. It failed before (the frontier jumped to the end).
  2. a547320 Time-boxed chunks, no off-screen redraw. - An idle chunk measures for at most 8 ms a turn (at least one block). The "more than 50 stale" threshold stays at 50. - A pass redraws only if a line or separator at or above the visible bottom moved. - While measuring, the frame follows the estimated height only when it is off by a page or more (and exactly once measuring is done). - Tests: with a zero budget a chunk measures one block (it measured 50); 200 pages measured below the screen ask for 0 redraws (they asked for one per chunk). Both fail with the old behaviour put back.

dd8c49a, found measuring the open: - Keys typed while the rest is still being measured stayed at about 7 ms (against 3.5 ms) even after measuring finished. Each key's edit joins the storage's one pending attribute-fixing range, which then runs to the document's end, and every later key fixed all of it again, inside setSelectedRanges. - The last idle chunk now fixes the storage's attributes once; that took 0–30 ms when measured. - Timing only: no deterministic test. After it, keys drop to 3–4 ms as soon as measuring ends.

  1. ac13bbd Seeded fuzz gate (PaginationFuzzTests), your approach. - Bare paged text view; 8 fixed seeds × 80 edits; with and without a window (4/3); paged and pageless. - The edits: - characters, wrapping inserts and Return; - a whole block deleted, and in-paragraph deletes; - pastes of 1–4 blocks with headings, and a block replaced by another kind; - two distant edits in one editing group; - a Backspace at a block's start, then its publication; - Pages toggled, and jumps with single idle chunks; - every block's attributes at once (kern, which moves every line, or metadata only): this is the more-than-50-stale path. - Every fourth edit it compares against the oracle (paged) or a whole plain layout (pageless): breaks, separators, every line origin (0.5 pt) and frame height. Lines laid out between comparisons stay laid out, so a missed invalidation shows. - About 120–137 comparisons, 60 of them begun with measuring incomplete; 2–3 s. - Fails with the live invalidation removed (origins off by 42–114 pt).
  2. d34e974 Disabled controls. - Inspector, iPhone toolbar and Format menu commands go through DocsModel.whenCommandsReady: they run now, or as soon as the pending input has been drawn. The last one asked for wins; it is dropped if editing becomes unavailable. A click during a key's wait is no longer a silent no-op, and ⌘B typed right behind a letter now applies. - Held for longer than 650 ms (the busy-button rule: a paused replica, a long IME composition), the controls show disabled via an observed commandsHeld. - A key's few milliseconds never set it, so the panel doesn't blink and isn't evaluated per key (the per-key render-isolation gate still holds). - Tests: a bold clicked while a key is pending applies once the key is drawn (it was dropped); commands held for long show disabled, and a key's wait never does. Each fails with its half removed.

Open and typing during open, Mac, paged (DOCS_RT_AUDIT_AT_OPEN=1: typing at the document's start as soon as it shows; 3 runs, load 115–230; in native/benchmarks/README.md, 0584b48):

| | shown | measured | keys, median | stalls > 16.7 ms / 40 keys | |---|---|---|---|---| | p20 | 0.34–0.48 s | 0.50–0.68 s | 2.1–2.7 ms (one run 6.2) | 2–3 (largest 87–144 ms, at the first key: the open's own turns) | | p200h | 1.3–1.6 s (replica open) | 2.3–2.7 s | 2.9–3.9 ms | 4–17, while the chunks run |

Gates at 0584b48:

  • swift test: 249 tests, 0 failures, 12 skipped.
  • test-iphone.sh: 20 tests, 0 failures, 3 skipped (probes).
  • snapshots.sh compare all: passed, pixel-identical. Mac: docs-editor 24, docs 22, docs-window 22. iPhone: docs-editor 20, docs-editor-ax3 4, docs 32. Baselines drawn on the same environment.
  • check-native.sh --mutations: passed, 20 mutations caught.
  • Mac release build: exit 0.
  • test-document-window.py, plain and with caret_fixture: PASS ×3 each.
  • Hub CI: passed.

Delta re-review of 3a9fc13..0584b48 — Claude Fable (model id claude-fable-5-2)

Verdict: APPROVE AFTER FIXES. My four asks are answered and hold up. The fixes needed are all in d34e974's queue (findings 1–3).

Run in a review-only worktree at 0584b48 (removed afterwards): swift test — 249 tests, 12 skipped, 0 failures; fuzz 123 comparisons, 63 with measuring incomplete, 2.0 s. Findings 1–4 were reproduced with throwaway probe tests against DocsModel (not committed).

Findings

  1. Medium — a queued command has no bound and no cancel. DocsModel.swift:885-891, 906-912. readyAction lives until commands are next enabled, however long that is. Probe: composition starts, Bold is clicked, 1.5 s pass (commandsHeld is true, the panel is grey), composition ends, and Bold then applies. So the user clicks, sees the control go disabled, carries on, and the command lands later. The same happens on any long hold (slow drain, the stalls at a large open). Fix: drop readyAction when the hold timer turns commandsHeld on (:901), so the queue lasts at most 650 ms and "shows disabled" means "your click did not take".
  1. Medium — the queued command runs against whatever is selected when it runs. DocsModel.swift:862-865 into :877. Probe: a key is pending, Bold is queued at a caret, the user then selects three characters elsewhere; when the key is drawn, those three characters are bolded. Running after the key's own caret move is right (that is what the user saw), but an explicit move by the user should cancel. Fix: clear readyAction in selectionMovedExplicitly() (:507), which already tells explicit moves from a key's expected one.
  1. Medium-low — the keyboard path is not queued, so ⌘B is still dropped. DocumentComposition.swift:37-43 (Mac performKeyEquivalent) and :114-118 (iOS UIKeyCommand) go to DocsModel.perform (DocsModel.swift:914-917), then DocumentCommands.perform, which refuses on isEnabled. Probe: model.perform("bold") with a key pending returns false and nothing applies later. The Format menu's ⌘B does go through ready, but as far as I can tell it never fires: the text view takes the key equivalent first, and the menu is disabled unless the text view is first responder. That ordering is from reading the code, not from a run in the app; please check. Type-then-⌘B is the likeliest way a person hits the pending window, so mouse and keyboard should behave the same: route the format, indent and outdent actions of perform through whenCommandsReady (undo and redo as they are).
  1. Low — "the last one asked for wins" drops the first of two clicks. DocsModel.swift:889. Probe: Bold then Italic inside one pending window gives italic only. Either a small FIFO or leave it and say so; rare once finding 1 bounds it.
  1. Low, a question — the whole panel, toolbar and Format menu now go grey during any composition longer than 650 ms. DocsModel.swift:498. That is every CJK phrase: one disable and one enable, two panel evaluations per composition. It is honest (commands cannot run then), and the test asserts it. Is it intended? If so, no change.
  1. Low — the queued closure holds the model strongly from the model. DocsFormatInspector.swift:30-33, EditorToolbar.swift:79-82, DocsEditorContext.swift:25-29. It is released on run or drop, so finding 1's bound closes it.

Checked and fine

  • Document switch, reader change, pause: each sets detail, inputPaused or sessionPaused, whose setters call refreshToolbarSelection; unavailable commands drop the queue without running it (:877). open, stop and the reset path all nil detail before anything could run it against another document.
  • Peer edit: the command builds a fresh DocumentCommands at run time, after the draw, with the selection the publication remapped. No stale content.
  • Composition commit order: compositionCommitted enqueues before compositionChanged(false), so a queued command runs after the committed text is drawn, not before.
  • No double-apply: readyAction is cleared before it runs; the re-entrant refresh from typingMarks' didSet finds nothing.
  • 0.1.7/0.1.8 hang rule: not reintroduced. commandsHeld is only read in bodies. It is written from the hold task and from refreshToolbarSelection, whose call sites already assigned toolbarSelection; the attach path still notifies on the next turn (DocumentSurface.swift:243-248).
  • Consistency: inspector, iPhone/Mac toolbar and Format menu all go through whenCommandsReady; no direct actions.* calls remain in the three. The keyboard is the exception (finding 3).
  • dd8c49a: one ensureAttributesAreFixed over the whole storage on the pass where measuring completes (DocsPagination.swift:433-441), never inside an edit. It does what lazy fixing would do at layout anyway, so no attribute or visual drift; the fuzz is green with it. Note: nothing gates it. Removing the line leaves every test green (it is a speed fix only), so only the benchmark numbers in the README protect it.
  • Timer guard (ask 1): correct; the chunk waits out of a window and the next layout or draw in a window reschedules (:317). A layout() forced on a windowless view would still measure the whole rest; I found no path that does that.
  • Time-boxed chunks (ask 2): correct, at least one block per chunk. The re-measure of up to 50 stale blocks and the O(blocks) break pass sit outside the 8 ms; fine at these sizes. The redraw rule and the page-sized height threshold while estimating are sound.
  • Fuzz gate (ask 3): meaningful. Mutations: not re-measuring stale blocks fails it; not marking breaks for newly measured blocks fails it. Dropping the more-than-50 reset survives, which looks like an equivalent mutation (it only changes the order of measuring).

Fable's delta review of 0584b48: all fixed, with the rulings applied. Branch now 84b6419, three commits, each test seen to fail with its fix removed. Not merged.

6091930 Bounding the command queue (findings 1, 2, 4–6 and the two rulings):

| Finding | Change | Test, and how it fails without the change | |---|---|---| | 1 (ruling) | A hold that is not a composition greys the controls after 650 ms and drops the queue. Nothing is queued while they are grey: grey means the click did not take. | testALongHoldGreysOutAndDropsTheQueue (a generation that hasn't caught up is the hold). Red with the drop removed. | | 2 | selectionMovedExplicitly() clears the queue. A key's own caret move is not an explicit move, so it doesn't clear it. | testMovingTheSelectionDropsAQueuedCommand. Red without the clear. | | 4 | The queue is FIFO and runs while commands are enabled. Each command may leave input pending again, and the next one then waits for it. | testCommandsQueuedInOneWaitRunInOrder. Red with last-wins. | | 5 (ruling) | A composition never greys, however long. No hold timer runs while composing. Commands queued during a composition run right after the commit. If a hold remains after the commit, the usual 650 ms rule applies from then on. | testACompositionNeverGreysAndItsCommandRunsAfterTheCommit replaces the test that asserted greying. Red with composition greying. | | 6 | The queue holds closures over DocumentCommands, which the model builds when it runs them; the views no longer capture the model. The hold task uses [weak self]. | (structural) |

e4137ea ⌘B typed behind a letter (finding 3):

  • DocsModel.perform sends bold, italic, code, indent, outdent and clear formatting through whenCommandsReady when commands are held. These are queued and bounded as above. Undo, redo, the hard break and ⌘K are unchanged.
  • Checked in the real Mac window: the smoke harness (test-document-window.py) types "z", sends ⌘B through NSApp.sendEvent (the app's own dispatch: key window, then menu), then types "w". ⌘B reaches DocsTextView.performKeyEquivalent (new probe counter, +1) and not the Format menu (its counter stays put). "w" is bold.
  • With the routing removed, the smoke fails with "⌘B typed behind a letter did not apply". The unit test through performKeyEquivalent fails too.

84b6419 A gate for dd8c49a:

  • testKeysAfterMeasuringFixOnlyTheirOwnAttributes counts the characters the text system fixes, by exchanging -[NSMutableAttributedString fixAttributesInRange:] in the test.
  • The setup: 200 pages in a window, keys at the start at 8 a second, each drawn by its publication, while the idle chunks measure and then after.
  • With the fix, 131,072 characters are fixed per key while measuring and 596 after (the key's own paragraph). Without it, 131,072 per key go on after measuring: red 3/3.
  • The UI probe counts the same per key (DOCS_RT_AUDIT_COUNT_FIXES=1). Without the fix, 2 runs in 3 kept fixing 65,536 characters a key (6.5 ms) after measuring; with it, 1 character a key.

Gates at 84b6419:

  • swift test: 254 tests, 0 failures, 12 skipped.
  • test-iphone.sh: 20 tests, 0 failures, 3 skipped (probes).
  • snapshots.sh compare all: passed, pixel-identical. Mac: docs-editor 24, docs 22, docs-window 22. iPhone: docs-editor 20, docs-editor-ax3 4, docs 32. Baselines drawn on the same environment.
  • check-native.sh --mutations: passed, 20 mutations caught.
  • test-document-window.py, plain and with caret_fixture: 4 PASS each, including the new ⌘B check.
  • Hub CI: passed.

Rebased onto main bde01ef; force-pushed perf/native-s1b at 1640f5e. The rebase was clean: 16 commits, no conflicts. Main only added the live-push spec, its harness and LivePushLatencyTests.swift.

  • LivePushLatencyTests: compiles against S1b unchanged; no S1b API it uses changed. Without its environment both tests skip ("Run native/benchmarks/live-push/run-native.sh").
  • swift test: 256 tests, 14 skipped, 0 failures, in two clean full runs. - An earlier full run, at load 360–680, failed two timing tests outside S1b's code. They then passed in isolation: - SignedInLaunchTests.testTheReplaceQuestionIsWithdrawnWithChangesUnsent: 3 of 4 runs. Its 0.5 s pump; S1a recorded the same flake at load ~700. - OfflineDurabilityTests.testRenameAfterTitlePOSTButBeforeBatchAckKeepsSuccessorTrigger: 4 of 4 runs.
  • check-native.sh: "Native checks passed"; its swift test was 256 tests, 0 failures.
  • snapshots.sh compare all: passed, pixel-identical. Mac: docs-editor 24, docs 22, docs-window 22. iPhone: docs-editor 20, docs-editor-ax3 4, docs 32. Baselines drawn on the same environment. - The run before, at load ~860, had 4 window screens "still changing after 3.0 seconds": the kit's limit under load. The re-run passed everything.
  • Hub CI at 1640f5e: passed.

Not merged.

Landed on main (squash) after Fable's two rounds and green hub CI at 1640f5e. Next: Docs native 0.1.13 to Mac + TestFlight.

Docs 0.1.13 (15) released to Mac (Sparkle) and TestFlight from main 6e0c0e0 (2026-11-26). It ships S1b, incremental pagination on the Mac (#173). It is native only, so there was no server deploy.

Tests on the release commit, after build-crdt.sh:

  • swift test --package-path native/apple: 256 tests, 0 failures, 14 skipped.
  • native/scripts/test-iphone.sh (iPhone 18 Pro, iOS 27.0 24A434): TEST SUCCEEDED. 20 tests, 0 failures. The 3 skips are env-gated: PhoneLargeDocumentTests (needs DOCS_PHONE_LARGE) and the two SurfaceTimingTests (need DOCS_RT_AUDIT_DOCS). BlockIndex, BlockRenderEquivalence, DeltaSafety (3), EditorRenderLoop (3), FlushTrigger (4), RenderIsolation and SurfaceLifecycle (4) all passed.
  • snapshots.sh compare all: green on the first run. Mac docs (22), docs-editor (24) and docs-window (22); iPhone docs-editor 20 + AX3 4 and docs 32. Every set says "baselines drawn on the same" (macOS 27.0.0, Xcode 27.2 27B52, runtime 27.0 24A434).
  • test-document-window.py: 4 PASS lines in the letter mode and 5 in DOCS_SMOKE_DRAFT=1. No test needed a re-run.

Mac 0.1.13 (15), Sparkle. Notarised (id f657e855-1a1e-4f30-a367-56f715e20b14).

  • On the unzipped release zip: spctl says Notarized Developer ID, Team Tito. Stapler validates it.
  • Entitlements are unchanged from 14: keychain groups .docs then .id, App Group 9U4A84C4WK.works.oficina, webcredentials:id.oficina.works. embedded.provisionprofile is there (profile e031a486…).
  • DocsMac --oficina-id-launch-check reported every line ok and exited 0.
  • Published to native-releases as release docs-15, feed commit c82770b801c7243618fb0ce62d3c26ae7909cce8. The public appcast lists 0.1.13 (15) first.
  • zip sha256 cbf625392d92f8f802bcdcd9d2757573a7951c5e90d5be460c897667aae61223 (15053855 bytes). An anonymous download gives the same hash and length.
  • The publish token (docs-release-0113) was revoked afterwards.

iPhone 0.1.13 (15), TestFlight.

  • Archived with Apple Distribution and the "Oficina docs iOS App Store 2026-11-14" profile.
  • The archive holds only DocsPhone.app, with no PlugIns, Frameworks or xctest.
  • Info.plist has 0.1.13 / 15 and ITSAppUsesNonExemptEncryption=false.
  • Uploaded with delivery 34b68ea0-47a6-468b-b9ad-8d473739062f. VALID after about 2 minutes, usesNonExemptEncryption=false.
  • internalBuildState is INBETATESTING. The "Oficina internal" group has access to all builds.

Deviation (same as 0.1.12): signed with the Apple Distribution identity 07E99055… from the login keychain, because oficina-distribution.keychain-db no longer unlocks with its stored password. The keychain search list was not changed.

Still stale: native/smoke/document-window/Package.resolved pins rastrillo/native at 529f356 while apple/ pins 0254817; SwiftPM re-resolves it on each smoke run, so the smoke ran on the release pin.

Next: Paul tries Pages-on typing on the Mac in build 15.