oficina / docs Public

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

Plain git — no account needed to clone.

Download

Download this file

1# Native realtime probes
2
3Brought onto main by S1a of the native redesign (spec
4`docs/superpowers/specs/2026-11-22-native-redesign-design.md` §7,
5"Measurement and targets"), from the 2026-11-21 audit branch
6`perf/native-realtime-audit`. Measurement tools, not gates: every probe
7skips unless its environment variable is set, and nothing here changes what
8the apps do. The counters are `DocsKit/DocsProbes.swift`, compiled only
9under the `DOCS_PROBES` condition: Package.swift sets it for debug builds
10(where `swift test` holds the §7 hard counters as gates), and the probe
11builds below pass `-Xswiftc -DDOCS_PROBES` to a release build. A shipping
12build is release without it. The audit's report is
13`oficina/native-levelup/docs-realtime-audit.md`; the baseline and the
14numbers after each slice are in `../README.md`.
15
16## Documents
17
18```sh
19cd fixtures && npm ci --ignore-scripts
20node generate-large-doc.mjs 20 /tmp/rt-audit/docs/p20.bin # 20 pages, built in one go
21node generate-large-doc.mjs 20 /tmp/rt-audit/docs/p20h.bin 1200 # plus 1,200 small edits from 20 clients
22node generate-large-doc.mjs 200 /tmp/rt-audit/docs/p200h.bin 10000 # §7's p200h, as check-native.sh builds it
23```
24
25A page is ~3,000 characters: five paragraphs with bold/italic runs, a heading
26every second page, a bullet list every fifth. The `h` variants carry the
27tombstones and fragmentation of a document that has been edited.
28
29## Build
30
31```sh
32cd native
33cargo build --manifest-path crdt/Cargo.toml --release --target wasm32-unknown-unknown --lib --locked
34cargo build --manifest-path host/Cargo.toml --release --target aarch64-apple-darwin --lib --locked
35xcodebuild -create-xcframework -library "$PWD/host/target/aarch64-apple-darwin/release/libdocs_native_host.a" \
36 -headers "$PWD/host/include" -output "$PWD/apple/Artifacts/DocsCRDT.xcframework"
37cd apple && swift build -c release --build-tests -Xswiftc -enable-testing
38GOTOOLCHAIN=go1.26.5 CGO_ENABLED=0 go test -c -o /tmp/rt-audit/docs.test ./internal/docs/ # from the repo root
39```
40
41The audit (on the old fixed 40M fuel budget) could not open documents over
42about 30 pages without raising `FUEL` by hand. The host's budget now grows
43with the instance (`native/host/src/lib.rs`, `BASE_FUEL` +
44`FUEL_PER_MEMORY_BYTE` …), so p50 and p200h open on production fuel and no
45edit is needed.
46
47## Probes
48
49| Probe | What it times |
50| --- | --- |
51| `RealtimeAuditTests/testRawHostCallPrices` | each WASM call the replica makes: module compile, open+apply, snapshot, project, Swift JSON decode |
52| `RealtimeAuditTests/testLocalKeystrokePipeline` | per keystroke, as `drainEdits` + `publishCurrent`: `command`, `presentation`, render, reconcile |
53| `RealtimeAuditTests/testRemoteUpdatePipeline` | per peer update, as `refresh`: `apply`, fresh-source `presentation`, render, reconcile |
54| `RealtimeAuditTests/testPersistenceAndSendCosts` | `DocsReplicaCache.commit` (memory and sealed disk), send merger, outbox enqueue/ack |
55| `RealtimeAuditE2ETests/*` via `run-e2e.py` | the production `DocsModel` + sealed store against the real server: request counts, bytes, ack and visibility latency, process CPU |
56| `RealtimeAuditIOSTests` (iOS simulator) | the iOS `DocsTextView`: `attributedText =` per publication vs reconciling into its storage |
57| `ui-probe` via `run-ui.py` | the real `DocsWorkspace` window: keyDown time, renders per key, main-queue stalls, peer update → visible |
58
59```sh
60cd native/apple
61DOCS_RT_AUDIT_DOCS=/tmp/rt-audit/docs DOCS_RT_AUDIT_ONLY=p1,p10,p20 \
62 swift test -c release -Xswiftc -enable-testing --skip-build --filter RealtimeAuditTests
63
64cd ../..
65python3 native/benchmarks/realtime/run-e2e.py /tmp/rt-audit/docs/p10.bin testEndToEndLocalTyping KEYS=40 CADENCE_MS=125 NOWAIT=1
66python3 native/benchmarks/realtime/run-e2e.py /tmp/rt-audit/docs/p10.bin testEndToEndRemoteUpdates KEYS=30 CADENCE_MS=125 BURST=10
67python3 native/benchmarks/realtime/run-e2e.py /tmp/rt-audit/docs/p10.bin testEndToEndIdle IDLE_S=40
68
69(cd native/benchmarks/realtime/ui-probe && swift build -c release -Xswiftc -DDOCS_PROBES)
70python3 native/benchmarks/realtime/run-ui.py /tmp/rt-audit/docs/p10.bin KEYS=40 PEER=30 [PAGED=0]
71native/benchmarks/realtime/run-matrix.sh /tmp/rt-audit/docs p20 p200h # the §7 matrix, RUNS=3 each
72
73# iOS (needs the aarch64-apple-ios-sim host slice in the XCFramework; DocsColophonTests
74# needs `import SwiftUI` to compile for iOS)
75TEST_RUNNER_DOCS_RT_AUDIT_DOCS=/tmp/rt-audit/docs xcodebuild test -scheme DocsNative-Package \
76 -destination 'platform=iOS Simulator,id=<udid>' -configuration Release \
77 -only-testing:DocsKitTests/RealtimeAuditIOSTests ENABLE_TESTABILITY=YES
78```
79
80The fixture server (`internal/docs/native_realtime_audit_test.go`) is the real
81authenticated app on loopback with a request log. Its sign-in returns three
82cookies (`rastrillo_attempt`, `rastrillo_last_signin`, `rastrillo_session`);
83the probe sends all of them. (`TestNativeKillServer` sends only `cookies[0]`,
84which is now `rastrillo_attempt`, so its native client is redirected; it was
85not run here.)
86