oficina / docs Public

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

Plain git — no account needed to clone.

Download

Native realtime probes

Brought onto main by S1a of the native redesign (spec docs/superpowers/specs/2026-11-22-native-redesign-design.md §7, "Measurement and targets"), from the 2026-11-21 audit branch perf/native-realtime-audit. Measurement tools, not gates: every probe skips unless its environment variable is set, and nothing here changes what the apps do. The counters are DocsKit/DocsProbes.swift, compiled only under the DOCS_PROBES condition: Package.swift sets it for debug builds (where swift test holds the §7 hard counters as gates), and the probe builds below pass -Xswiftc -DDOCS_PROBES to a release build. A shipping build is release without it. The audit's report is oficina/native-levelup/docs-realtime-audit.md; the baseline and the numbers after each slice are in ../README.md.

Documents

cd fixtures && npm ci --ignore-scripts
node generate-large-doc.mjs 20 /tmp/rt-audit/docs/p20.bin          # 20 pages, built in one go
node generate-large-doc.mjs 20 /tmp/rt-audit/docs/p20h.bin 1200    # plus 1,200 small edits from 20 clients
node generate-large-doc.mjs 200 /tmp/rt-audit/docs/p200h.bin 10000 # §7's p200h, as check-native.sh builds it

A page is ~3,000 characters: five paragraphs with bold/italic runs, a heading every second page, a bullet list every fifth. The h variants carry the tombstones and fragmentation of a document that has been edited.

Build

cd native
cargo build --manifest-path crdt/Cargo.toml --release --target wasm32-unknown-unknown --lib --locked
cargo build --manifest-path host/Cargo.toml --release --target aarch64-apple-darwin --lib --locked
xcodebuild -create-xcframework -library "$PWD/host/target/aarch64-apple-darwin/release/libdocs_native_host.a" \
  -headers "$PWD/host/include" -output "$PWD/apple/Artifacts/DocsCRDT.xcframework"
cd apple && swift build -c release --build-tests -Xswiftc -enable-testing
GOTOOLCHAIN=go1.26.5 CGO_ENABLED=0 go test -c -o /tmp/rt-audit/docs.test ./internal/docs/   # from the repo root

The audit (on the old fixed 40M fuel budget) could not open documents over about 30 pages without raising FUEL by hand. The host's budget now grows with the instance (native/host/src/lib.rs, BASE_FUEL + FUEL_PER_MEMORY_BYTE …), so p50 and p200h open on production fuel and no edit is needed.

Probes

| Probe | What it times | | --- | --- | | RealtimeAuditTests/testRawHostCallPrices | each WASM call the replica makes: module compile, open+apply, snapshot, project, Swift JSON decode | | RealtimeAuditTests/testLocalKeystrokePipeline | per keystroke, as drainEdits + publishCurrent: command, presentation, render, reconcile | | RealtimeAuditTests/testRemoteUpdatePipeline | per peer update, as refresh: apply, fresh-source presentation, render, reconcile | | RealtimeAuditTests/testPersistenceAndSendCosts | DocsReplicaCache.commit (memory and sealed disk), send merger, outbox enqueue/ack | | RealtimeAuditE2ETests/* via run-e2e.py | the production DocsModel + sealed store against the real server: request counts, bytes, ack and visibility latency, process CPU | | RealtimeAuditIOSTests (iOS simulator) | the iOS DocsTextView: attributedText = per publication vs reconciling into its storage | | ui-probe via run-ui.py | the real DocsWorkspace window: keyDown time, renders per key, main-queue stalls, peer update → visible |

cd native/apple
DOCS_RT_AUDIT_DOCS=/tmp/rt-audit/docs DOCS_RT_AUDIT_ONLY=p1,p10,p20 \
  swift test -c release -Xswiftc -enable-testing --skip-build --filter RealtimeAuditTests

cd ../..
python3 native/benchmarks/realtime/run-e2e.py /tmp/rt-audit/docs/p10.bin testEndToEndLocalTyping KEYS=40 CADENCE_MS=125 NOWAIT=1
python3 native/benchmarks/realtime/run-e2e.py /tmp/rt-audit/docs/p10.bin testEndToEndRemoteUpdates KEYS=30 CADENCE_MS=125 BURST=10
python3 native/benchmarks/realtime/run-e2e.py /tmp/rt-audit/docs/p10.bin testEndToEndIdle IDLE_S=40

(cd native/benchmarks/realtime/ui-probe && swift build -c release -Xswiftc -DDOCS_PROBES)
python3 native/benchmarks/realtime/run-ui.py /tmp/rt-audit/docs/p10.bin KEYS=40 PEER=30 [PAGED=0]
native/benchmarks/realtime/run-matrix.sh /tmp/rt-audit/docs p20 p200h   # the §7 matrix, RUNS=3 each

# iOS (needs the aarch64-apple-ios-sim host slice in the XCFramework; DocsColophonTests
# needs `import SwiftUI` to compile for iOS)
TEST_RUNNER_DOCS_RT_AUDIT_DOCS=/tmp/rt-audit/docs xcodebuild test -scheme DocsNative-Package \
  -destination 'platform=iOS Simulator,id=<udid>' -configuration Release \
  -only-testing:DocsKitTests/RealtimeAuditIOSTests ENABLE_TESTABILITY=YES

The fixture server (internal/docs/native_realtime_audit_test.go) is the real authenticated app on loopback with a request log. Its sign-in returns three cookies (rastrillo_attempt, rastrillo_last_signin, rastrillo_session); the probe sends all of them. (TestNativeKillServer sends only cookies[0], which is now rastrillo_attempt, so its native client is redirected; it was not run here.)