oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Native replica typing probe — 2026-09-13

This bounded review experiment exercises the real CRDTReplica actor and its statically linked WASM host. It is not a UI responsiveness, device, release-build, or web/native performance parity benchmark. No production algorithm was changed. The executable was an arm64 macOS Swift debug test build. Other integration work was running on the machine, so these single samples are directional evidence.

| Mode | Characters | Elapsed seconds | Snapshot bytes | Total emitted update bytes | Largest update bytes | Client IDs | | --- | ---: | ---: | ---: | ---: | ---: | ---: | | Fresh presentation after every character | 100 | 1.221 | 1,635 | 1,802 | 27 | 101 | | Fresh presentation after every character | 1,000 | 26.734 | 15,901 | 17,867 | 27 | 1,001 | | Fresh presentation after every character | 5,000 | stopped, no completed sample | — | — | — | — | | Fresh presentation after each 100-character batch | 100 | 0.014 | 159 | 127 | 127 | 2 | | Fresh presentation after each 100-character batch | 1,000 | 0.120 | 1,192 | 1,178 | 127 | 11 | | Fresh presentation after each 100-character batch | 5,000 | 0.673 | 5,792 | 5,858 | 127 | 51 | | One retained source, individual character commands | 100 | 0.137 | 159 | 1,810 | 28 | 2 | | One retained source, individual character commands | 1,000 | 1.813 | 1,060 | 19,755 | 28 | 2 | | One retained source, individual character commands | 5,000 | 11.442 | 5,060 | 99,755 | 28 | 2 |

The fresh-source mode acknowledges each presentation immediately and retires the old generation before the next publication. The retained-source control never publishes another presentation, approximating a burst whose callbacks still refer to one displayed generation; it is not a proposed safe replacement algorithm. Batch mode inserts 100 ASCII characters per command and then presents. All modes start with one paragraph and assert the resulting text length at every milestone. Wall time includes actor commands, internal snapshots/projections, source retention, and (where specified) presentations and their selection-anchor resolution. It excludes initial open/paragraph creation, network, native text layout, and rendering. Milestone snapshot/client queries add a little work to subsequent cumulative times.

Per-character new client IDs materially increase work and persisted CRDT overhead in this workload. At 1,000 characters the fresh-source snapshot is 15,901 bytes, about 0.19% of the 8 MiB bridge boundary. The bridge does not expose an encoded state-vector command, so exact vector bytes were not measured. For these fresh workloads, client IDs and clocks fit unsigned 32-bit varints: a conservative encoded-vector bound is 5 + 10 * clientCount bytes (five bytes each for ID and clock plus five for count). That is at most 10,015 bytes for the measured 1,001 clients. This is a bound, not an observed size or a long-document capacity claim. Latency becomes material well before the measured byte boundary. Rich formatting, large documents, long sessions, peer updates, and device memory limits remain unmeasured; batching is not validated here as a correctness-preserving fix.

The first 5,000 fresh-generation run was stopped after roughly four minutes to release SwiftPM's build lock for integration. SwiftPM buffered its XCTest output, so no completed 5,000 result or intermediate metrics were recovered. The smaller fresh-source sample and both controls were then run directly with xctest, which does not hold the SwiftPM lock and emits milestones immediately. A separate 100 character sample took 1.244 seconds with a 1,638-byte snapshot/101 clients; small size differences reflect randomly assigned client IDs.

Repeating the probe

NativePerformanceProbeTests.swift is intentionally outside the normal test source tree. Temporarily copy it into native/apple/Tests/DocsKitTests/, build the test bundle once with a 100-character limit, and remove the copied source after measurement. Use the actual built test-bundle path for your machine:

DOCS_PROBE_MODE=fresh DOCS_PROBE_COUNT=100 swift test --package-path native/apple --filter NativePerformanceProbeTests
DOCS_PROBE_MODE=fresh DOCS_PROBE_COUNT=1000 /Applications/Xcode.app/Contents/Developer/usr/bin/xctest -XCTest DocsKitTests.NativePerformanceProbeTests/testTypingProbe native/apple/.build/arm64-apple-macosx/debug/DocsNativePackageTests.xctest

Set mode to batch or retained and count to 5000 for the controls. Run modes sequentially and bound runtime. Recorded executable SHA-256: 3ce4222fa0981fc444f85bb858cdebca921eecf26c5eb50d4e44657ed62b2485. Original local logs: /private/tmp/docs-probe-fresh1000.log, /private/tmp/docs-probe-batch.log, /private/tmp/docs-probe-retained.log.

Acknowledged identical-source reuse followup

After the independently reviewed presentation(..., allowReuse: true) change, mode reuse explicitly acknowledges the current published generation before every next character and requests reuse. Every character still performs a presentation and selection-anchor resolution. Only the same live source with byte-identical committed state can be returned; this does not batch away commands or render steps.

| Characters | Elapsed seconds | Snapshot bytes | Total update bytes | Largest update | Client IDs | | --- | ---: | ---: | ---: | ---: | ---: | | 100 | 0.329 | 159 | 1,810 | 28 | 2 | | 1,000 | 3.303 | 1,060 | 19,755 | 28 | 2 | | 5,000 | 30.845 | 5,060 | 99,755 | 28 | 2 |

The 1,000-character sample falls from 26.734 to 3.303 seconds (about 8.1 times faster in these individual runs), with client count bounded at two. The 5,000 sample now completes, but there is no completed pre-change 5,000 timing to form a ratio. It remains slower than the retained-source control, which omits all presentation/anchor work, and much slower than 100-character batches. These data support reduced source churn; they do not establish a device latency budget or solve the cost of projecting and snapshotting long documents on every keystroke. The source-reuse regression separately proves peer divergence and undo still publish fresh generations and preserve peer content, and default/no-acknowledgement calls still use fresh sources.

This followup was also measured amid integration builds. Its initial separate 100-character compile-phase sample took 2.727 seconds, versus 0.329 seconds in the direct run, demonstrating machine-load sensitivity. The table is the single direct run's cumulative milestones, not selected best timings. Direct log: /private/tmp/docs-probe-reuse5000.log. Repeat using DOCS_PROBE_MODE=reuse. Followup executable SHA-256: b08998210ac83bec46a8cb2d62c51c0e2792b0c65e647f52fa58eaee879a3c55.

Engine cost per keystroke (2026-11-22, perf/native-realtime-engine)

host/examples/realtime.rs prices, through the production interpreter and fuel, what CRDTReplica does per typed character: display_edit on the displayed source, the update applied to the authority, the selection's two anchors resolved, and the authority's presentation (project_delta). Documents come from fixtures/generate-large-doc.mjs (see docs-realtime-audit in oficina/native-levelup).

cd native && cargo build --manifest-path crdt/Cargo.toml --release --target wasm32-unknown-unknown --lib --locked
cargo run --release --manifest-path host/Cargo.toml --example realtime -- /tmp/rt-audit/docs/p*.bin

Rendering: baseline and S1a (2026-11-22/24, perf/native-s1a)

Spec 2026-11-22-native-redesign-design.md §7, "Measurement and targets". Probes: realtime/ (its README). Mac: the UI probe, Release with -DDOCS_PROBES, on an Apple M1 Max, macOS 27.0, the in-memory store. A (baseline) is main after phase 2 plus the probes (the first S1a commit, "the realtime probes on main", whose renderer is main's); B is the S1a branch. A and B were run interleaved (run-matrix.sh's runs, A then B, per row), because the machine was shared: the load average was never under 4 (it was 12–150 for the table below, and 300–1,000 for the first, separate baseline, whose timings are therefore not used). Timings are indicative; the counters are exact. iPhone figures are the simulator on the Mac's CPU, DocsKit in Debug (SurfaceTimingTests, test-iphone.sh with TEST_RUNNER_DOCS_RT_AUDIT_DOCS), not a phone.

Hard counters, per event after open (B; A in brackets). The same gates run in swift test and test-iphone.sh (RenderIsolationTests):

| Counter | Per key | Per peer change | Per sync-status / selection change | |---|---|---|---| | Whole-document renders | 0 (A: 3.6–4.5) | 0 (A: 0.8–1.0; p200h 2.0–2.7) | 0 | | Block renders | 1 (gate ≤ 3) | ≤ 1 per touched block | 0 | | Host body evaluations | 0 (A: 3.6–4.5) | 0 (A: 0.8–2.7) | 0 | | iOS attributedText assignments | 0 (A: 1 per publication) | 0 | 0 | | Text-storage edits | 1 Mac, 2 iOS (the typed character, then the publication's ids) | 1 | 0 |

Timings, medians of three interleaved runs (A → B):

| Measure | p20 | p200h | |---|---|---| | Mac keyDown, pageless, 40 keys | 1.2 → 1.4 ms (p95 19 → 2.7) | 6.4 → 6.6 ms, noisy both sides (A 2.4/6.4/7.0, B 6.6/6.8/2.3) | | Mac keyDown, pageless, 200 keys | 1.19 → 1.29 ms; p95 18.7 → 1.4 ms | — | | Mac keyDown, paged | 65 → 65 ms (S1b: pagination is unchanged) | 648 → 669 ms (S1b) | | Main-queue stalls > 16.7 ms, 40 keys, pageless | 90 → 0 | 87–95 → 1–3 | | Peer change, main-thread busy, pageless (everything on the main thread, network included) | 73 → 23 ms | 576–704 → 16–22 ms | | Peer change, publication to reconciled, pageless (DocsProbes.publicationMs) | ≈ 1 ms | ≈ 2.8 ms | | Peer change, paged | 117 → 81 ms busy; the reconcile's storage edit still repaginates the whole document (S1b) | 888–1,146 → 200–209 ms | | iPhone, one-block publication + layout | 53 → 0.7 ms | 542 → 4.8 ms |

S1a meets its two timing targets: the iPhone per publication (≤ 4 ms at p20, ≤ 8 ms at p200h) and the peer change's main-thread time measured from publication to reconciled (≤ 5 / ≤ 10 ms). Measured as the whole main thread's busy time per peer change, which also counts the network, the replica's answer and drawing, p20 is 23 ms. The Mac paged keyDown and stall targets wait for S1b, as the plan says: updatePagination still copies and measures the whole document per storage edit.

S1b: incremental pagination and the keystroke path (2026-11-26, perf/native-s1b)

Same probes and machine as S1a, with step 0's additions: "keyDown to drawn" is the key and then the window's layout and display pass, run at once (event → text storage → layout → display; the text's own drawing happens at the transaction commit after it, about 0.2 ms); the display pass is also timed alone; line requests are TextKit's, counted inside the containers. A is main plus the probes (facc40e), B the branch. The load average was 150–600 throughout (other agents' builds), so timings are indicative and the counters exact. p20 and p200h are three interleaved runs each (A then B, per row; medians); the other rows are single runs.

Step 0, the cause. Paged, two passes of updatePagination per key copied and laid out the whole document (36 ms at p20) and layout() laid out the whole live container (29 ms): 759 line requests a key at p20, 7,694 at p200h, to each of the live and the measurement containers. Pageless, layout()'s whole-container layout cost 6–9 ms a key at p200h. Outside pagination, the display pass after every key spent about 3 ms in SwiftUI's hosting views (the workspace, the Format inspector and the menus read state that moves twice a key), and the toolbar's state, refreshed five times a key, walked the whole projection (0.5 ms a refresh at p200h). A third of keyDown under this load is AppKit hiding the cursor (SLSObscureCursor, a WindowServer round trip): the system's. At p200h paged every page label (200) was drawn on every frame.

| Mac, 40 keys at 8/s | p1 | p5 | p20 | p50 | p200h | |---|---|---|---|---|---| | keyDown, paged | 3.7 → 1.9 ms | 17.7 → 2.1 ms | 66.3 → 2.4 ms | 179 → 2.4 ms | 680 → 3.4 ms | | keyDown to drawn, paged | 6.8 → 2.0 ms | 21.2 → 2.1 ms | 69.5 → 2.5 ms | 182 → 2.5 ms | 683 → 3.5 ms | | keyDown, pageless | 1.3 → 1.4 ms | 1.3 → 2.1 ms | 1.7 → 2.6 ms | 2.1 → 3.9 ms | 8.7 → 2.6 ms | | keyDown to drawn, pageless | 4.5 → 1.4 ms | 4.6 → 2.1 ms | 4.8 → 2.7 ms | 5.5 → 3.9 ms | 12.1 → 2.7 ms | | Line requests per key, live (paged) | 6 → 5 | 195 → 5 | 759 → 6 | 1,895 → 9 | 7,694 → 6 (max 21) | | Stalls > 16.7 ms, paged | 0 → 0 | 40 → 0 | 40 → 0 | (one 7 s block) → 0 | (one 27 s block) → 0 | | Stalls > 16.7 ms, pageless | 0 → 0 | 0 → 0 | 0 → 0 | 1 → 1 | 10, 1, 1 → 0, 1, 0 |

The display pass after a key: 3.1–4.1 → 0.05 ms everywhere. p20 over 200 keys: paged median 1.8 ms, p95 2.4 ms; pageless 1.7 / 2.0 ms. Per peer change, all main-thread busy: paged p20 94 → 32 ms, p200h 315 → 39 ms; pageless unchanged (30 → 32, 47 → 42 ms). Pages off or on at the end of a 200-page document (unit test, load 450–600): 0.50–0.63 s, the live layout laid out again from the first break to the visible end (8,500 lines; the live container is laid out contiguously, the §7 fallback).

iPhone (simulator, DocsKit Debug; SurfaceTimingTests.testKeystroke). Unchanged by S1b, and the spec's plan for it does not hold (see the discussion): per key median 1.3–2.7 ms, but a key that changes a line count lays the rest of the document out again inside UIKit's TextKit 1 (max 59 → 10,454 line requests, 4 ms at p1 to 250–440 ms at p200h), and opening p200h lays all of it out (0.6–3.2 s).

After Fable's review (#173). Opening, and typing as soon as the document shows (DOCS_RT_AUDIT_AT_OPEN=1: at its start, while the rest is still measured in idle chunks of at most 8 ms), paged, three runs, load 115–230: p20 shows 0.34–0.48 s after the window is asked for and is measured 0.50–0.68 s after; keys median 2.1–2.7 ms (one run 6.2), 2–3 stalls over 40 keys, the largest at the first key (87–144 ms, the open's own turns). p200h shows 1.3–1.6 s after (the replica's open) and is measured 2.3–2.7 s after; keys median 2.9–3.9 ms, 4–17 stalls while the chunks run. Before the last idle chunk fixed the storage's attributes, keys typed during measuring stayed at about 7 ms (against 3.5) until the next document was opened.

S3: the iPhone editor on TextKit 2 (2026-11-28, native/iphone-document)

PhoneLargeDocumentTests (DocsPhoneTests, TEST_RUNNER_DOCS_PHONE_LARGE=1), p200h paged (200 pages, 1,260 paragraphs), iPhone 18 Pro simulator, iOS 27.0, DocsKit Debug, three runs at load 8–9:

| | TextKit 1 (as shipped) | TextKit 2 (S3) | Target | |---|---|---|---| | Open, main thread to the first screen | 1.27 s, the whole document | 159–168 ms (render 125–128 ms), 11 of 1,260 paragraphs laid out | ≤ 250 ms | | Per key, median (40 keys mid-document, on screen) | 1.3–2.7 ms | 6.4–6.5 ms | ≤ 8 ms | | Worst key (the worst are those that change a line count) | 250–480 ms | 12.4–12.7 ms | ≤ 16.7 ms | | Fragments laid out per key | (10,454 line requests) | median 1, max 6 | | | Jump to the end before anything below the first screen is laid out | (already laid out) | 465–472 ms, once (spec §7 Fallback) | |

After the jump: 354 page breaks, 0 laid out away from where they were placed; the caret on its glyph's line; 41 lines near the end compared with a fresh view laid out whole, 0 differ. Breaks are per paragraph (DocsPhonePages): a paragraph that would cross a page's body moves to the next page's top, the space carried by the previous paragraph's layout fragment; measurements are fragment-local, because TextKit 2 leaves stale origins on fragments below an edit. PhonePaginationTests checks a 20-page document after a Return, a deleted paragraph, a paste and typing: no line in a gap or across a bottom margin, every break where it was placed, every line where a whole layout puts it (it fails with the break's space removed).

The 72.7 pt caret. On TextKit 1, UIKit ignores the custom container's push of each page's first line (the 72 pt top margin, plus 0.7 pt of font metrics): glyphs and caret are both drawn 72 pt above where the layout manager says the line is, in paged and pageless alike, at the first line as at the end (testTheTextKit1CaretAtTheEnd, offsets 72.60–72.67 pt). So it was real and visible: no iPhone page had a top margin and the bottom margin was doubled (S0's "iPhone page-1 top margin missing"); the probe measured it by comparing the caret with container coordinates. On TextKit 2 the margin is textContainerInset and the caret sits on its line.

After Fable's review of S3 (#180). A peer's edit above the screen no longer throws the layout below it away: TextKit 2's fragments are stacked again by a walk from the top before UIKit lays the screen out, and the screen's first fragment is kept where it was on screen. p200h, a peer's 20 keys on page 2 with the screen at the middle, through the surface's publication path, three runs at load 9–10:

| | Before | After | |---|---|---| | Per peer key, median | ~465 ms (all of it laid out again) | 13.2–13.6 ms, 8.7–8.9 ms of it the surface's publication | | Worst peer key moving at most one break | ~465 ms | 15.8–17.2 ms (median of the three 16.5) | | A line cascading 40 page breaks above the screen | ~465 ms | 29.7–31.0 ms, once | | Paragraphs laid out again from the top | 1,000+ per key | 0 |

The screen's text did not move on any key. Local typing, the open and the jump are unchanged: open 160–165 ms (12 of 1,260 paragraphs), per key median 6.5–6.9 ms and max 9.5–10.5 ms, the jump 478–482 ms with 0 breaks misplaced and 0 of 41 lines away from a whole layout. On a key only the breaks through the screen's end are rebuilt; those below are rebuilt while idle, which starts for them (until Fable's delta review it did not, and they waited for a scroll to reach them). A moved break still rebuilds its paragraph's fragment (TextKit 2 stacks a fragment's new height only after laying it out again), so a cascade costs about 0.4 ms a break.

After Fable's delta review (F1–F8). The screen is kept on the caret when it is on screen, else on its middle (F4); idle builds the breaks a key leaves below the screen (F2) and finishes the restack once typing pauses (F3). p200h, the same peer probe, three runs at load 10–11: per peer key median 11.5–11.8 ms (7.5–7.7 ms of it the publication); worst key moving at most one break 14.2–14.6 ms (a fourth run 15.3); the 40-break cascade 27.7–28.9 ms; 0 paragraphs laid out again; the line at the screen's middle still on every key. Open 156–165 ms, local keys median 6.2 ms and max 10.1–10.5 ms, the jump 455–476 ms with 0 breaks misplaced and 0 of 41 lines off.