oficina / docs Public

Docs native S1a: the baseline and S1a's numbers, and the iPhone timing probe

native/benchmarks/README.md records §7's counters and timings, main after
phase 2 (with the probes) against the branch, run interleaved because the
machine was shared. SurfaceTimingTests (DocsPhoneTests, env-gated) times
the iPhone's one-block publication before and after. BUILDING.md says what
test-iphone.sh now runs and where DOCS_PROBES is defined.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 2f8d4fe47c868d9de48a8045957136a82e58aa6f parent 3ad5cd2
4 files changed, +148 −4
  • native/BUILDING.md +14 −4
  • native/apple/Tests/DocsKitTests/SurfaceTimingTests.swift +86 −0
  • native/benchmarks/README.md +47 −0
  • native/ios/project.yml +1 −0
diff --git a/native/BUILDING.md b/native/BUILDING.md
index f074332..5e7e184 100644
--- a/native/BUILDING.md
+++ b/native/BUILDING.md
@@ -29,10 +29,20 @@ are caught, restoring every changed source and saving logs under
`native/build/mutation-logs`. Do not run mutations concurrently with builds.
`native/scripts/test-iphone.sh` runs the tests that need UIKit's text view
-(DocsPhoneTests in `ios/project.yml`: today the editor render-loop regression
-of TestFlight 0.1.10 (12), whose Mac half runs in `swift test`) in the iOS
-27.0 simulator. It is not in CI, which has no simulator: run it before
-changing `NativeDocumentTextView` or the render.
+(DocsPhoneTests in `ios/project.yml`: the editor render-loop regression of
+TestFlight 0.1.10 (12), and the redesign's S1a tests of `DocumentSurface`:
+the flush triggers, delta safety, the block index, block render
+equivalence, render isolation with §7's counters; their Mac half runs in
+`swift test`) in the iOS 27.0 simulator. It is not in CI, which has no
+simulator: run it before changing `NativeDocumentTextView`,
+`DocumentSurface` or the render.
+
+§7's counters (`DocsKit/DocsProbes.swift`) compile under `DOCS_PROBES`:
+Package.swift defines it for debug builds, so `swift test` and
+test-iphone.sh hold the hard counters as gates (`RenderIsolationTests`);
+a release build, the one that ships, carries none of it. The timings are
+measured by `native/benchmarks/realtime` (its README), and the numbers are
+in `native/benchmarks/README.md`.
The apps bundle every font in Docs' shared list
(`internal/fonts/fonts.json`): `native/apple/Sources/DocsKit/Fonts` is a
diff --git a/native/apple/Tests/DocsKitTests/SurfaceTimingTests.swift b/native/apple/Tests/DocsKitTests/SurfaceTimingTests.swift
new file mode 100644
index 0000000..5cfbbb7
--- /dev/null
+++ b/native/apple/Tests/DocsKitTests/SurfaceTimingTests.swift
@@ -0,0 +1,86 @@
+#if os(iOS)
+import Foundation
+import UIKit
+import XCTest
+@testable import DocsKit
+
+/// §7's iPhone row: main-thread time per one-block publication, before S1a
+/// (the whole `attributedText` assigned, as `applyRender` did) and after
+/// (`DocumentSurface`: the one block rendered and reconciled), each with
+/// the layout that follows. A probe, not a gate: skipped unless
+/// DOCS_RT_AUDIT_DOCS names a directory of generate-large-doc.mjs
+/// documents (TEST_RUNNER_DOCS_RT_AUDIT_DOCS through xcodebuild).
+@MainActor final class SurfaceTimingTests: XCTestCase {
+ func testOneBlockPublication() async throws {
+ guard let dir = ProcessInfo.processInfo.environment["DOCS_RT_AUDIT_DOCS"] else { throw XCTSkip("Set DOCS_RT_AUDIT_DOCS") }
+ let names = (ProcessInfo.processInfo.environment["DOCS_RT_AUDIT_ONLY"] ?? "p20,p200h").split(separator: ",").map(String.init)
+ DocsFonts.register()
+ for name in names {
+ let replica = CRDTReplica(guid: "timing-" + name)
+ try await replica.open(update: try Data(contentsOf: URL(fileURLWithPath: "\(dir)/\(name).bin")))
+ var projection = try await replica.projection()
+ await replica.close()
+ let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 402, height: 874))
+ window.makeKeyAndVisible()
+ let block = projection.children.count / 2
+ for paged in [true, false] {
+ // Before: the whole text assigned per publication.
+ let before = DocsTextView(frame: window.bounds)
+ before.paged = paged
+ window.addSubview(before)
+ before.attributedText = NativeTextProjection.render(projection)
+ before.layoutIfNeeded()
+ var whole: [Double] = []
+ var current = projection
+ for _ in 0..<8 {
+ current.children[block] = Self.appending("x", to: current.children[block])
+ let start = ContinuousClock.now
+ before.attributedText = NativeTextProjection.render(current)
+ before.layoutIfNeeded()
+ whole.append(Self.ms(start))
+ }
+ before.removeFromSuperview()
+ // After: the surface.
+ let after = DocsTextView(frame: window.bounds)
+ after.paged = paged
+ window.addSubview(after)
+ let surface = DocumentSurface()
+ surface.attach(after)
+ current = projection
+ var revision: UInt64 = 1
+ surface.apply(DocumentSurface.Publication(generation: 1, projection: current, revision: revision, dirty: nil))
+ after.layoutIfNeeded()
+ var perBlock: [Double] = []
+ for _ in 0..<8 {
+ current.children[block] = Self.appending("x", to: current.children[block])
+ revision += 1
+ let start = ContinuousClock.now
+ surface.apply(DocumentSurface.Publication(generation: 1, projection: current, revision: revision, dirty: [current.children[block].id]))
+ after.layoutIfNeeded()
+ perBlock.append(Self.ms(start))
+ }
+ after.removeFromSuperview()
+ print(String(format: "SURFACE TIMING %@ paged=%d: attributedText+layout median %.2f ms; surface+layout median %.2f ms (n=8; %@ / %@)", name, paged ? 1 : 0,
+ Self.median(whole), Self.median(perBlock), whole.map { String(format: "%.1f", $0) }.joined(separator: " "), perBlock.map { String(format: "%.1f", $0) }.joined(separator: " ")))
+ }
+ projection = CRDTProjection(children: [], canUndo: false, canRedo: false)
+ window.isHidden = true
+ }
+ }
+ static func ms(_ start: ContinuousClock.Instant) -> Double {
+ let d = start.duration(to: .now); return Double(d.components.seconds) * 1000 + Double(d.components.attoseconds) / 1e15
+ }
+ static func median(_ values: [Double]) -> Double { let s = values.sorted(); return s.isEmpty ? .nan : s[s.count / 2] }
+ static func appending(_ text: String, to node: CRDTNode) -> CRDTNode {
+ var node = node
+ if var runs = node.runs, !runs.isEmpty { runs[0].insert += text; node.runs = runs; return node }
+ if var children = node.children {
+ for index in children.indices {
+ let changed = appending(text, to: children[index])
+ if changed != children[index] { children[index] = changed; node.children = children; return node }
+ }
+ }
+ return node
+ }
+}
+#endif
diff --git a/native/benchmarks/README.md b/native/benchmarks/README.md
index 5815eb8..945611c 100644
--- a/native/benchmarks/README.md
+++ b/native/benchmarks/README.md
@@ -113,3 +113,50 @@ Documents come from `fixtures/generate-large-doc.mjs` (see
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 (28efd51, the first S1a
+commit, 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.
diff --git a/native/ios/project.yml b/native/ios/project.yml
index 30d6d73..b14acc2 100644
--- a/native/ios/project.yml
+++ b/native/ios/project.yml
@@ -140,6 +140,7 @@ targets:
- path: ../apple/Tests/DocsKitTests/BlockIndexTests.swift
- path: ../apple/Tests/DocsKitTests/BlockRenderEquivalenceTests.swift
- path: ../apple/Tests/DocsKitTests/RenderIsolationTests.swift
+ - path: ../apple/Tests/DocsKitTests/SurfaceTimingTests.swift
dependencies:
- package: DocsNative
product: DocsKit