#if DOCS_PROBES import Foundation /// Counters for the editor's rendering path (spec 2026-11-22 §7, /// "Measurement and targets"). Compiled only under the `DOCS_PROBES` /// condition: Package.swift sets it for debug builds, where `swift test` /// holds the hard counters as gates, and the release probe builds pass /// `-Xswiftc -DDOCS_PROBES` (native/benchmarks/realtime). A shipping build /// is release without the flag, so it carries none of this. /// /// Main thread only; nothing here changes what the editor does. public enum DocsProbes { /// `NativeTextProjection.render`: the whole document. nonisolated(unsafe) public static var wholeRenders = 0 nonisolated(unsafe) public static var wholeRenderMs = 0.0 /// `NativeTextProjection.renderBlock`: one top-level block. nonisolated(unsafe) public static var blockRenders = 0 nonisolated(unsafe) public static var blockRenderMs = 0.0 /// `DocumentRenderReconciliation.apply`, whole storage or one range. nonisolated(unsafe) public static var reconciles = 0 nonisolated(unsafe) public static var reconcileMs = 0.0 /// `updateNSView` / `updateUIView` of the text view's representable. nonisolated(unsafe) public static var viewUpdates = 0 nonisolated(unsafe) public static var viewUpdateMs = 0.0 /// Body evaluations of the view that hosts the text view. nonisolated(unsafe) public static var hostBodies = 0 /// Body evaluations of the document window's own views that typing must /// not reach (S1b step 0: each key re-evaluated them, 2–4 ms a key): /// the workspace, and the Mac's Format inspector. nonisolated(unsafe) public static var workspaceBodies = 0 /// Formatting commands by path: the text view's own key equivalent /// (⌘B in the editor) and the Format menu (the smoke test checks which /// one a typed ⌘B takes). nonisolated(unsafe) public static var keyEquivalentCommands = 0 nonisolated(unsafe) public static var menuCommands = 0 nonisolated(unsafe) public static var inspectorBodies = 0 /// iOS `UITextView.attributedText` assignments by the editor. nonisolated(unsafe) public static var attributedTextAssignments = 0 /// Publications applied to the text view, and the main-thread time from /// a publication reaching the main actor to its storage being reconciled. nonisolated(unsafe) public static var publications = 0 nonisolated(unsafe) public static var publicationMs = 0.0 /// Line-fragment requests TextKit makes to the text view's own container /// (`DocsPageTextContainer.lineFragmentRect`): every line it lays out /// again, ours or its own re-layout (S1b's gate), and to the Mac's /// measurement container (`measureLineRequests`). nonisolated(unsafe) public static var lineRequests = 0 /// iOS, TextKit 2: layout fragments made (one per paragraph laid out). nonisolated(unsafe) public static var layoutFragments = 0 /// iOS: paragraphs whose page-break space changed (DocsPhonePages). nonisolated(unsafe) public static var pageBreakChanges = 0 /// iOS: layout fragments made while DocsPhonePages measured. nonisolated(unsafe) public static var measureFragments = 0 nonisolated(unsafe) public static var breakParagraphs = 0 /// iOS: paragraphs whose layout was thrown away to lay them out again /// from the top (DocsPagedTextView.paginate, a screen placed at an /// estimate: spec §7 Fallback). nonisolated(unsafe) public static var relaidParagraphs = 0 /// iOS: walks from the top over what is laid out, to stack fragments /// below an edit again (DocsPhonePages.ensureLayout). nonisolated(unsafe) public static var restackWalks = 0 nonisolated(unsafe) public static var measureLineRequests = 0 /// Mac pagination passes, and their main-thread time. nonisolated(unsafe) public static var paginations = 0 nonisolated(unsafe) public static var paginationMs = 0.0 /// Redraws of the visible rect a pagination pass asked for, and whether /// the last pass left measuring incomplete (the probe's open timing). nonisolated(unsafe) public static var paginationRedraws = 0 nonisolated(unsafe) public static var measuring = false /// The text view's own layout (Mac `layout()`, iOS `layoutSubviews`). nonisolated(unsafe) public static var textLayouts = 0 nonisolated(unsafe) public static var textLayoutMs = 0.0 /// The text view's drawing (Mac `draw(_:)`, iOS `draw(_:)`). nonisolated(unsafe) public static var draws = 0 nonisolated(unsafe) public static var drawMs = 0.0 /// `DocsModel.refreshToolbarSelection`: the toolbar and inspector state. nonisolated(unsafe) public static var toolbarRefreshes = 0 nonisolated(unsafe) public static var toolbarRefreshMs = 0.0 /// `DocsModel.enqueue`: a typed command handed to the model. nonisolated(unsafe) public static var commands = 0 nonisolated(unsafe) public static var commandMs = 0.0 public static func reset() { wholeRenders = 0; wholeRenderMs = 0; blockRenders = 0; blockRenderMs = 0 reconciles = 0; reconcileMs = 0; viewUpdates = 0; viewUpdateMs = 0 hostBodies = 0; attributedTextAssignments = 0; publications = 0; publicationMs = 0 workspaceBodies = 0; inspectorBodies = 0 lineRequests = 0; layoutFragments = 0; pageBreakChanges = 0; measureFragments = 0; breakParagraphs = 0; relaidParagraphs = 0; restackWalks = 0; measureLineRequests = 0; paginations = 0; paginationMs = 0; paginationRedraws = 0 textLayouts = 0; textLayoutMs = 0; draws = 0; drawMs = 0 toolbarRefreshes = 0; toolbarRefreshMs = 0; commands = 0; commandMs = 0 } public static var summary: String { String(format: "wholeRenders=%d (%.1f ms) blockRenders=%d (%.1f ms) reconciles=%d (%.1f ms) viewUpdates=%d (%.1f ms) hostBodies=%d attributedText=%d publications=%d (%.1f ms)", wholeRenders, wholeRenderMs, blockRenders, blockRenderMs, reconciles, reconcileMs, viewUpdates, viewUpdateMs, hostBodies, attributedTextAssignments, publications, publicationMs) } /// The keystroke path's parts (S1b, step 0). public static var pathSummary: String { String(format: "lineRequests=%d measureLineRequests=%d paginations=%d (%.1f ms) textLayouts=%d (%.1f ms) draws=%d (%.1f ms) toolbarRefreshes=%d (%.1f ms) commands=%d (%.1f ms) workspaceBodies=%d inspectorBodies=%d", lineRequests, measureLineRequests, paginations, paginationMs, textLayouts, textLayoutMs, draws, drawMs, toolbarRefreshes, toolbarRefreshMs, commands, commandMs, workspaceBodies, inspectorBodies) } static func now() -> UInt64 { DispatchTime.now().uptimeNanoseconds } static func ms(since start: UInt64) -> Double { Double(DispatchTime.now().uptimeNanoseconds - start) / 1e6 } } #endif