Commit 9cf7ae99af
Verified · cmc
Layout: unified · split
docs/review-2026-11-21.md added +488
| @@ -0,0 +1,488 @@ | ||
| 1 | # orgstar review, 2026-11-21 | |
| 2 | ||
| 3 | Scope: issue #96. Speed, memory and energy, size, and code quality of the whole codebase at 1bdd0d3 (version 1.2.0 plus the roadmap handoff document). The review covers what can be measured from the command line on one Mac, and the Swift sources read for the code-quality questions. Nothing was measured on an iPhone, iPad or Watch, and nothing in Instruments' GUI; section 7 lists those with steps. Issue #109 (code scanning) is out of scope. | |
| 4 | ||
| 5 | Facts, for calibration: | |
| 6 | ||
| 7 | | | | | |
| 8 | |---|---| | |
| 9 | | Version | 1.2.0, commit 1bdd0d3 | | |
| 10 | | Size | 403 Swift files and 104,801 lines under `Sources/`; `ios/` holds the Xcode project, plists and assets, no Swift | | |
| 11 | | Tests | 1,148 tests in 10 test targets, 28,772 lines; all pass, with one exception described in 5.6 | | |
| 12 | | Machine | MacBook Pro Mac14,10, Apple M2 Pro (8 performance and 4 efficiency cores), 16 GB | | |
| 13 | | Software | macOS 27.0.1 (26A434), Xcode 27.2 (27B52), Swift 6.4.2, Emacs 31.1 | | |
| 14 | | Power | Low power mode off. The first test run and the Xcode builds ran on battery, the gates and benchmarks on mains | | |
| 15 | ||
| 16 | Method. `swift test`, the gates and both Xcode builds are the commands in `CONTRIBUTING.org`. Parse, index, agenda, save, export and table timings come from throwaway Swift Testing files run with `swift test -c release` and deleted afterwards; each number is the best of three runs unless a range is given. Synthetic inputs: a mixed document (headings with planning lines and drawers, paragraphs with markup, lists, tables, source blocks, footnotes) at 100 kB to 10 MB, and a folder of 10,000 files with eight headings each (19 MB). Launch and hang numbers come from the release Developer ID build (`scripts/build-app.sh`, arm64), started with the `ORGSTAR_*` development hooks against a throwaway data folder and a 1,003-file folder (14 MB, 59,751 headings, 49,400 links), with `ORGSTAR_PERF=1` and `log stream` reading the `perf` category. Profiles are `sample` at 1 ms. | |
| 17 | ||
| 18 | ## 1. Verdict | |
| 19 | ||
| 20 | The module structure is sound and the core is fast where it was measured before: parsing is linear at 85 ms per MB up to 10 MB, the index answers a search over 80,000 headings in 11 to 55 ms, saving a 10 MB file takes 35 ms, and tangling takes 155 ms per MB. Line coverage of the shared modules is 75 to 98 %, and a launch-open-quit run leaks nothing from the app's code. | |
| 21 | ||
| 22 | Three things are wrong and affect ordinary use on the Mac today: | |
| 23 | ||
| 24 | 1. The performance gates fail. Opening a file takes 5.6 times the gate (560 ms for the 1 MB section, gate 100 ms) because the editor restyles the whole file during `init` when stars are not hidden, which is the default. The change went in two days after the gates were recorded, and nothing runs the gates. | |
| 25 | 2. The backlinks pane, shown by default, recomputes on the main thread after every pause in typing and builds a regular expression for every link in the workspace. With 49,400 links the window is blocked for 1.6 to 9.8 seconds at launch and again after each pause. | |
| 26 | 3. Styling cost grows with the square of the file size. Styling 1 MB takes 1.2 s and 10 MB takes 129 s; typing in a 10 MB file takes 77 ms per key. The iOS editor styles the whole file synchronously at load, so it inherits the worst case. | |
| 27 | ||
| 28 | Two defects lose data in narrow cases: shared captures on iOS are deleted from the inbox before they are filed, and several configuration writers replace a file they failed to read. | |
| 29 | ||
| 30 | The largest size cost is structural: the widget and share extensions link all of `OrgApp`, 38 MB each as universal binaries with a 7 MB copy of SwiftMath's fonts, to read three JSON snapshot types. | |
| 31 | ||
| 32 | ## 2. Speed | |
| 33 | ||
| 34 | ### 2.1 Gates | |
| 35 | ||
| 36 | `ORGSTAR_GATES=1 swift test -c release --filter GateTests`, four runs, medians. The earlier column is `docs/plans/2026-10-04-performance.md`, taken on an unnamed M-series Mac, so the ratios are indicative; the cause below does not depend on the machine. | |
| 37 | ||
| 38 | | File | Measure | 2026-10-04 | Today | Gate | | | |
| 39 | |---|---|---|---|---|---| | |
| 40 | | Single 1 MB section | open | 76 ms | 560 ms | 100 ms | fails | | |
| 41 | | | typing p95 | 7.0 ms | 9.8 ms | 16 ms | | | |
| 42 | | | blank line p95 | 8.1 ms | 11.1 ms | 16 ms | | | |
| 43 | | | memory | 30.4x | 38.1x | 45x | | | |
| 44 | | 5,000-row table (312 kB) | open | 38 ms | 133 ms | 100 ms | fails | | |
| 45 | | | typing p95 | 3.2 ms | 4.5 ms | 16 ms | | | |
| 46 | | | blank line p95 | 8.8 ms | 10.0 ms | 16 ms | | | |
| 47 | | | memory | 42.9x | 50.7x | 45x | fails | | |
| 48 | | 3,000 entries with drawers (821 kB) | open | | 236 ms | 100 ms | fails | | |
| 49 | | | typing / blank line p95 | | 9.2 / 9.2 ms | 16 ms | | | |
| 50 | | | memory | | 24.7x | 45x | | | |
| 51 | | `csg.org` (1,545 kB) | open | 75 ms | 219 ms | 155 ms | fails | | |
| 52 | | | typing p95 | 6.5 ms | 11.5 ms | 16 ms | | | |
| 53 | | | blank line p95 | 7.3 ms | 12.0 ms | 16 ms | | | |
| 54 | | | memory | 9.6x | 11.6x | 10x | fails | | |
| 55 | ||
| 56 | Where the open time goes, for the 1 MB section: `DocumentState(bytes:)` 82 ms (the parse), `OrgEditor(document:)` 461 ms, scroll view and window 8 ms. A profile of `OrgEditor.init` puts 3,826 of 3,839 samples in `restyle` called from `Sources/OrgEditorAppKit/OrgEditor.swift:125`: | |
| 57 | ||
| 58 | ```swift | |
| 59 | if !indented || !hideStars { restyleOutsideEditing(0..<utf16Length) } | |
| 60 | ``` | |
| 61 | ||
| 62 | `hideLeadingStars` defaults to false (`Sources/OrgCore/Commands/Command.swift:71`, `Sources/OrgApp/UserConfig.swift:163`), so with default settings every open styles the whole file before the first frame, and the chunked styling that `load` sets up two lines earlier does nothing useful. The line came in with 265b9d6 on 2026-10-06. In the app the same path shows as 387 ms in `PaneView.makeEditor` when the 1 MB file opens, 289 ms of it at this line. | |
| 63 | ||
| 64 | The gates are skipped unless `ORGSTAR_GATES` is set, there is no CI, and no release script runs them, so the failure went unseen for six weeks. The M1 Air run (issue 2) is still owed. | |
| 65 | ||
| 66 | ### 2.2 Large files | |
| 67 | ||
| 68 | The gate measurement applied to the mixed document: | |
| 69 | ||
| 70 | | | 1 MB | 10 MB | | |
| 71 | |---|---|---| | |
| 72 | | Parse (`OrgParser.parse`) | 85 ms | 853 ms | | |
| 73 | | Open in the editor | 503 ms | 18.9 s | | |
| 74 | | Typing p95 | 7.5 ms | 76.6 ms | | |
| 75 | | Blank line p95 | 7.6 ms | 77.5 ms | | |
| 76 | | Editor heap over file size | 36.4x | 35.2x | | |
| 77 | | Styling the whole file after open | 1.17 s | 129 s | | |
| 78 | | `DocumentState.apply`, one character, ASCII text | 0.2 ms | 1.6 ms | | |
| 79 | | `DocumentState.apply`, one character, text with umlauts | 3.3 ms | 33.5 ms | | |
| 80 | | Outline (`Presentation.outline`) | 2.5 ms | 27 ms | | |
| 81 | | Tree heap over file size | 18.1x | 17.8x | | |
| 82 | ||
| 83 | Styling is quadratic: 6.5 ms for 60 kB, 1.17 s for 1 MB, 129 s for 10 MB. The profile shows where: 2,369 of 3,826 samples are in `NSMutableRLEArray insertObject:range:` under `NSTextStorage.addAttribute`, moving the tail of the attribute run array. `restyle` (`Sources/OrgEditorAppKit/OrgEditor+Styling.swift:19-57`) first adds a paragraph style per line across the range, which creates one run per line, and then applies each role from the start, so every insertion shifts all the runs after it. The same shift is what makes typing in a 10 MB file take 77 ms: an edit in the middle restyles a paragraph in front of several hundred thousand runs. On the Mac the styling after open runs in run-loop turns, so the window stays usable while two minutes of work drain. | |
| 84 | ||
| 85 | The document model has its own cost on non-ASCII text. `DocumentState.applyGroup` (`Sources/OrgDocument/DocumentState.swift:85-105`) copies the whole string per edit and finds positions with `String.Index(utf16Offset:)` (`:178-182`), which is linear when the string is not ASCII. One umlaut in a 10 MB file makes each keystroke cost 33.5 ms in the model alone, twice the 16 ms budget before any styling. | |
| 86 | ||
| 87 | The iOS editor has no gates and no tests. `MobileEditor.load` styles the whole file synchronously (`Sources/OrgstarMobile/MobileEditor+Styling.swift:12-18`), `restyleAll` does so again when markup, spelling or images are toggled (`:99-105`), and files under 60,000 UTF-16 units are restyled whole on every edit (`:166`). It calls the same `Presentation` functions and the same attribute calls as the Mac editor, so the Mac's 1.17 s for 1 MB is about the best a phone can be expected to do, as one main-thread block at open, and a 10 MB file can be expected to run into the watchdog. Needs a device to confirm (section 7). | |
| 88 | ||
| 89 | Folding and highlighting were not timed apart from the gates, which cover both. Table alignment is in 2.6. | |
| 90 | ||
| 91 | ### 2.3 Main-thread hangs over 100 ms | |
| 92 | ||
| 93 | From the release app with `ORGSTAR_PERF=1`, which logs every main-thread wait of 100 ms or more. | |
| 94 | ||
| 95 | | Where | Blocked | Cause | | |
| 96 | |---|---|---| | |
| 97 | | Every launch | two or three waits of 154 to 318 ms before the editor appears | not profiled | | |
| 98 | | Opening the 1 MB file | 387 ms | `OrgEditor.init`, 2.1 | | |
| 99 | | Backlinks pane, 1 MB file selected | 1.6 s | below | | |
| 100 | | Backlinks pane, a small file with a heading selected | 3.2 s per pass, two or three passes: 6.5 to 9.8 s | below | | |
| 101 | | Inspector pane, hidden, 1 MB file | 362 ms | below | | |
| 102 | | TAB in a 5,000-row table | 616 ms | 2.6 | | |
| 103 | | Agenda refresh with 10,000 agenda files | 502 ms | 2.5 | | |
| 104 | ||
| 105 | Backlinks. `BacklinksPane` sits under the outline and both are shown by default (`Sources/Orgstar/ContentView.swift:95-97`). Its `.task(id:)` key includes `session.editVersion` and the heading at the caret (`Sources/Orgstar/BacklinksPane.swift:35`), so `refresh()` runs after every 300 ms pause in typing and whenever the caret enters another heading. `refresh()` is synchronous on the main actor and calls `WorkspaceModel.backlinks` once for the file and once for the heading (`:68`, `:76`); that reads every link in the index and tests each with `Backlinks.links` (`Sources/OrgApp/WorkspaceModel.swift:445-456`). In the profile 75 % of the time is the regex literal at `Sources/OrgCore/Links/Backlinks.swift:45`, which Swift parses again on every evaluation, and 10 % is `NSRegularExpression(pattern:)` built per call in `Links.unescape` (`Sources/OrgCore/Links/Links.swift:38`). The cost is about 33 to 65 µs per link per pass, so a workspace with 5,000 links already blocks for a third of a second after each pause. | |
| 106 | ||
| 107 | Inspector. `InspectorPane` runs its `.task` while `inspectorShown` is false, the default (`Sources/Orgstar/InspectorPane.swift:44`, `Sources/Orgstar/ContentView.swift:284`). Each run builds a `DocumentModel` and a clock report for the whole file on the main actor (`:143`). | |
| 108 | ||
| 109 | Two more places do index work in a view body or on the main actor without a measurement in the app: the Mac's search results call `workspace.search` and `workspace.overlay` inside `body` (`Sources/Orgstar/ContentView.swift:276`), as does the iOS search screen (`Sources/OrgstarMobile/SearchScreen.swift:26`). `overlay` rebuilds a `FileRecord` from the buffer's bytes whenever the text changed (`Sources/OrgApp/WorkspaceModel.swift:479-488`); that is a full parse plus the semantic pass, 212 ms per MB. | |
| 110 | ||
| 111 | ### 2.4 Index | |
| 112 | ||
| 113 | 10,000 files, 19 MB, 80,000 headings, on the internal SSD. | |
| 114 | ||
| 115 | | | | | |
| 116 | |---|---| | |
| 117 | | First build (`Reconciler.reconcile(root:)`) | 11.8 s, one thread | | |
| 118 | | Memory during the build | +249 MB | | |
| 119 | | Index size | 62 MB, 3.3 times the text | | |
| 120 | | Reconcile with nothing changed | 0.99 s, of which the directory scan is 0.97 s | | |
| 121 | | Reconcile one changed path | 20.5 ms, of which `fileStates(root:)` is 13.4 ms | | |
| 122 | | `index.files()` | 4.7 ms | | |
| 123 | | Search, one to three terms | 11 to 55 ms | | |
| 124 | | `links()` / `nodes()` / `outline(maxLevel: 3)` / `tags()` | 147 / 116 / 151 / 12 ms | | |
| 125 | ||
| 126 | The build reads every file, keeps the bytes and the finished record of each in memory (`Sources/OrgWorkspace/Reconciler.swift:69-130`), and writes them in one transaction (`Sources/OrgIndex/IndexStore.swift:201-218`). The store is a `DatabaseQueue` with the default journal mode (`:76-80`; `PRAGMA journal_mode` returns `delete`), so every reader waits for that transaction, including `reloadFiles()` and search on the main actor. | |
| 127 | ||
| 128 | A whole-root scan runs at launch, when file events are dropped, and after trashing or renaming a file (`WorkspaceModel.rescan(containing:)`, `Sources/OrgApp/WorkspaceModel.swift:430-435`). It costs about 97 µs per file with nothing changed. | |
| 129 | ||
| 130 | Of the 62 MB, 18.4 MB is the FTS content table (a second copy of every heading's text) and 13.7 MB the FTS index. The `properties`, `timestamps` and `clocks` tables and the rows of `tags` with `inherited = 1` are written for every heading (`IndexStore.swift:248-266`) and no query reads them; the same holds for the `todo`, `is_done`, `priority`, `archived` and `parent_ordinal` columns of `headings`. In this corpus they are 5.4 MB with their indexes. The agenda does not use the index at all; it parses files itself. | |
| 131 | ||
| 132 | ### 2.5 Agenda and search | |
| 133 | ||
| 134 | The agenda keeps an `AgendaSource` per file, parsed from the file's text, in an `AgendaSourceCache` (`Sources/OrgApp/AgendaModel.swift:10-16`). | |
| 135 | ||
| 136 | | 10,000 files | | | |
| 137 | |---|---| | |
| 138 | | Building the sources, cold (read and parse) | 7.5 s, one thread | | |
| 139 | | Heap held by one cache | 176 MB, 9 times the text | | |
| 140 | | `attributesOfItem` for every file | 502 ms | | |
| 141 | | Day / week / month, 23 to 108 dated entries | 27 / 188 / 796 ms | | |
| 142 | | Day / week / month, three dated entries per file (30,725 items today) | 12.1 / 13.0 / 16.9 s | | |
| 143 | | The same three views over 1,000 of those files | 174 / 266 / 630 ms | | |
| 144 | | TODO list / text search / tag match | 447 / 387 / 149 ms | | |
| 145 | ||
| 146 | Each refresh stats every agenda file on the main actor before it hands the parsing to a detached task (`AgendaModel.swift:187-202`, the `attributesOfItem` call at `:194`). That is a 50 ms block per 1,000 files on every refresh, cache hit or not. Refreshes are frequent: the agenda views, the sidebar, the widgets' snapshot and the reminders each refresh, and on the Mac, with orgstar+ unlocked or the menu bar item on, the widgets' refresh follows every pause in typing with no delay when reminders are off (`Sources/Orgstar/ContentView.swift:499-505`, `:1168-1173`, `:1188-1190`). | |
| 147 | ||
| 148 | Each `AgendaModel` has its own cache. The Mac creates five (`Sources/Orgstar/AgendaView.swift:111`, `BoardView.swift:33`, `AgendaSidebar.swift:34`, `ContentView.swift:1176` and `:1191`), iOS two that do not share (`Sources/OrgstarMobile/MobileModel.swift:84`, `BoardScreen.swift:28`). Each one reads and parses every agenda file and holds the result. | |
| 149 | ||
| 150 | `Agenda.list` scans every source once per day shown (`Sources/OrgCore/Agenda/Agenda.swift:192-199`), so a month costs 30 day views. With many items on one day the cost grows faster than the item count (70 times the time for 10 times the files); a real agenda does not have 30,000 items on a day, so this matters less than the per-day scan. | |
| 151 | ||
| 152 | Search Notes is the index search above: 11 to 55 ms at 80,000 headings. | |
| 153 | ||
| 154 | ### 2.6 Tables | |
| 155 | ||
| 156 | `TableCommand(.align)` on a 5,000-row, three-column table takes 586 ms. `tableNextField` calls `tableAlign()` unconditionally (`Sources/OrgCore/Commands/Table.swift:289-293`), so every TAB in a table realigns all of it: 63 ms at 500 rows, 616 ms at 5,000. Org realigns only when a field changed width. | |
| 157 | ||
| 158 | ### 2.7 Save, external changes, conflicts | |
| 159 | ||
| 160 | `Saver.save` through `CoordinatedFileSystem` on the internal SSD: 7 ms median for 1 MB (15 ms worst of five), 35 ms for 10 MB (43 ms). A save reads the file three times, writes it once and reads the backup (`Sources/OrgDocument/Saving.swift:58-81`, `FileStorage.swift:23-45`). A coordinated read alone is 0.7 ms for 1 MB. | |
| 161 | ||
| 162 | These run on the main actor: `DocumentSession.open` (`Sources/OrgApp/DocumentSession.swift:253`), `save` (`:444`), `fileChanged` (`:1083`) and the conflict commands. On a local disk that is invisible. On iCloud Drive or a File Provider folder a coordinated read can wait for a download or for another coordinator while the window is blocked. Not measured: this Mac's iCloud Drive holds the owner's notes, and Syncthing was not set up for the review (section 7). | |
| 163 | ||
| 164 | ### 2.8 Export and tangling | |
| 165 | ||
| 166 | | | 100 kB | 300 kB | 1 MB | | |
| 167 | |---|---|---|---| | |
| 168 | | HTML | 134 ms | 379 ms | 1.25 s | | |
| 169 | | Markdown | 126 ms | 356 ms | 1.20 s | | |
| 170 | | LaTeX | 514 ms | 1.50 s | | | |
| 171 | | ODT | 423 ms | 1.22 s | | | |
| 172 | | ASCII | 1.65 s | 12.8 s | | | |
| 173 | | ASCII, footnotes removed | 1.07 s | 7.94 s | | | |
| 174 | | Tangle, as the app calls it | 19 ms | 48 ms | 155 ms | | |
| 175 | ||
| 176 | HTML, Markdown, LaTeX and ODT are linear over these sizes. ASCII is not: three times the text takes 7.7 times as long. One cause is `ASCIIRenderer.definition`, which walks the whole tree for each footnote reference (`Sources/OrgCore/Export/ASCIIExport.swift:1369-1370`); the export is still superlinear without footnotes, from a path not profiled. LaTeX, ASCII and ODT were not timed one by one above 300 kB. At that rate ASCII needs about two and a half minutes for 1 MB, and at 10 MB it was stopped after six minutes. | |
| 177 | ||
| 178 | All the exporters pay for regex literals written inline: `OrgCore` has 197 of them, none in a `static let`, and each is parsed again when its line runs (profile: `Regex.init(_regexString:version:)` under `LaTeXRenderer.footnote`, `Sources/OrgCore/Export/LaTeXExport.swift:1875`). Quick Look's preview is `HTMLExport.page`, so a 1 MB file takes about 1.3 s to preview. | |
| 179 | ||
| 180 | `Tangle.run` parses the file again for every block when no tree is passed (`Sources/OrgCore/Compute/Tangle.swift:61`); the app always passes one (`Sources/OrgApp/TangleWriter.swift:66`, `:73`), so only other callers would pay: 60 s for 1 MB with 770 blocks. | |
| 181 | ||
| 182 | PDF and Word export go through WebKit and `NSAttributedString` and were not timed. | |
| 183 | ||
| 184 | ### 2.9 Launch | |
| 185 | ||
| 186 | Mac, release Developer ID build, arm64, warm (the binary and its libraries in the file cache). Time from `Process.run()` to the first window of at least 200 points appearing in `CGWindowListCopyWindowInfo`. | |
| 187 | ||
| 188 | | | First window | Footprint a few seconds later | | |
| 189 | |---|---|---| | |
| 190 | | Empty data folder | 467 and 565 ms | 58 to 63 MB | | |
| 191 | | 1,003-file folder, small file selected, nine launches | 393 to 446 ms | 100 to 145 MB | | |
| 192 | | Same folder, 1 MB file selected | 399 to 427 ms | 192 to 217 MB | | |
| 193 | ||
| 194 | The window appears before the editor has its text; after it come the waits in 2.3. Cold launch (after a restart) could not be taken without `sudo purge` or a reboot. The first run of a newly built binary took 6.1 s, which is macOS checking the new executable. | |
| 195 | ||
| 196 | ### 2.10 Widgets, the watch app, the Live Activity | |
| 197 | ||
| 198 | Read from the code; timings need devices. | |
| 199 | ||
| 200 | - Widgets read one JSON snapshot and build a timeline with an entry per change in the day (`Sources/OrgstarWidgets/AgendaTimeline.swift:32-47`). `AgendaSnapshot.write` skips the write and the reload when days and colors are unchanged (`Sources/OrgApp/AgendaSnapshot.swift:238-243`). The design is cheap. | |
| 201 | - While orgstar+ is locked on iOS, `updateWidgets` calls `reloadAllTimelines()` every time it runs (`Sources/OrgstarMobile/MobileModel.swift:301-306`), which is after every edit, with nothing new for the widgets to read. | |
| 202 | - The widget extension links all of `OrgApp` (section 4), so its process starts with a 10 MB text segment, GRDB, SwiftMath and the rest mapped. | |
| 203 | - The watch app and its complications link only `OrgWatchData` and are 3 MB in total. | |
| 204 | - iOS has no background modes and no `BGTaskScheduler`. Indexing, reminders and widget snapshots are refreshed only while the app is in the foreground, so background energy is close to nothing and widgets go stale when files change by sync while the app is closed. | |
| 205 | ||
| 206 | ## 3. Memory and energy | |
| 207 | ||
| 208 | Memory per open file, from the gates: 25 to 51 times the file size on the heap after styling (2.1), 35 times for the mixed 10 MB document, which is 352 MB. The tree alone is 18 times the text. `DocumentState` also holds the original bytes, the decoded source text and the current text (`Sources/OrgDocument/DocumentState.swift:25-27`). Two gate limits are exceeded: 50.7x against 45x for the table, 11.6x against 10x for `csg.org`. A 10 MB file on an iPhone is likely to be ended for memory; needs a device. | |
| 209 | ||
| 210 | Other holders, all scaling with the workspace: 176 MB per agenda cache at 10,000 files, times the number of caches (2.5); 249 MB transient during the first index build (2.4); the iOS Spotlight indexer reads every changed file into one array and submits one batch (`Sources/OrgstarMobile/SpotlightIndexer.swift:56-76`), so the first index of a workspace holds all its text twice. | |
| 211 | ||
| 212 | Leaks: `leaks --atExit` on a launch that opens the 1 MB file and quits reports 416 leaks, 26,400 bytes, all in system XPC connections (`LNDaemonApplicationInterface`) and dispatch sources; none has app code as its owner. Retain cycles over a long session and with several large buffers need Instruments (section 7). | |
| 213 | ||
| 214 | Energy, from the code: | |
| 215 | ||
| 216 | - The Mac's mode line reads `.git/HEAD` every 5 seconds for as long as a pane exists, whether or not the app is active (`Sources/Orgstar/ModeLine.swift:105-112`). | |
| 217 | - Reminders, widgets and Spotlight are recomputed after each edit: on iOS one second after typing stops (`Sources/OrgstarMobile/OrgstarMobileApp.swift:155-168`), each pass statting every agenda file. | |
| 218 | - The side panes in 2.3 burn main-thread time after each pause. | |
| 219 | ||
| 220 | ## 4. Size | |
| 221 | ||
| 222 | ### 4.1 Bundles | |
| 223 | ||
| 224 | Release builds as the commands in `CONTRIBUTING.org` produce them. The Xcode builds are universal and unsigned and have not been through an archive, which strips symbols; the `__TEXT` column is what stripping leaves untouched. The zip is `ditto -c -k`, a rough stand-in for the download. | |
| 225 | ||
| 226 | | Bundle | Size | Zip | Main executable | `__TEXT`, arm64 | | |
| 227 | |---|---|---|---|---| | |
| 228 | | Mac App Store, `Orgstar macOS`, arm64 + x86_64 | 179 MB | 60.9 MB | 81.3 MB | 26.5 MB | | |
| 229 | | Developer ID, `scripts/build-app.sh`, arm64 only | 102 MB | 34.9 MB | 41.6 MB | 27.2 MB | | |
| 230 | | iOS, `Orgstar iOS`, simulator, arm64 + x86_64 | 226 MB | 96.4 MB | 81.5 MB | 26.2 MB | | |
| 231 | | Watch app with its widgets, inside the iOS bundle | 3.05 MB | | 0.74 MB | 0.11 MB | | |
| 232 | ||
| 233 | Per extension, universal binaries, with arm64 `__TEXT`: | |
| 234 | ||
| 235 | | Extension | Mac App Store | iOS | `__TEXT`, arm64 | Links | | |
| 236 | |---|---|---|---|---| | |
| 237 | | Widgets | 45.4 MB | 45.7 MB | 9.7 to 9.8 MB | `OrgApp` and everything under it, plus a 7.1 MB copy of SwiftMath's fonts | | |
| 238 | | Share | | 45.0 MB | 9.6 MB | the same | | |
| 239 | | Quick Look | 16.0 MB | 15.9 MB | 4.9 MB | `OrgCore` | | |
| 240 | | Spotlight | 16.0 MB | | 4.9 MB | `OrgCore` | | |
| 241 | ||
| 242 | The device and App Store download sizes (thinned, compressed by Apple) need an archive and App Store Connect's report (section 7). | |
| 243 | ||
| 244 | The Developer ID binaries are not stripped: neither `scripts/build-app.sh` nor `scripts/release-mac.sh` calls `strip`. `strip -x` takes the four executables from 77.3 MB to 54.6 MB per architecture (main 41.6 to 30.1, widgets 19.6 to 12.7, Quick Look 8.1 to 5.9, Spotlight 8.1 to 5.9), about 45 MB of a universal DMG's contents. | |
| 245 | ||
| 246 | ### 4.2 Resources | |
| 247 | ||
| 248 | | Resource | Size | Where | | |
| 249 | |---|---|---| | |
| 250 | | Tree-sitter grammars, compiled in | about 14.2 MB of object code per architecture: Haskell 3.6, C++ 3.3, Ruby 2.0, Bash 1.3, Rust 1.1, C 0.6, the other twelve with the scanners 2.4 | main executable | | |
| 251 | | Highlight queries | 0.3 MB | 16 small bundles | | |
| 252 | | Diagram and math scripts (`OrgMathJax`) | 8.75 MB: `mermaid.min.js` 5.29, `tex-svg-full.js` 2.17, `viz-global.js` 1.27 | both apps | | |
| 253 | | SwiftMath fonts | 7.1 MB per copy: 12 math fonts with their tables | one copy in the Mac app and one in its widget extension; three copies on iOS (app, widgets, share) | | |
| 254 | | iOS app icons | 18.1 MB `Assets.car`: 13 icon sets at 0.6 to 2.1 MB each | iOS app | | |
| 255 | | Mac icon previews | 3.07 MB, 26 PNGs | Mac app | | |
| 256 | | String catalogs | 0.1 MB per language, five languages; 1,151 strings | every bundle that has UI | | |
| 257 | | Themes | in code | | | |
| 258 | | Sparkle | 2.76 MB | Developer ID only | | |
| 259 | ||
| 260 | The grammars are more than half of the main executable's 26.5 MB of `__TEXT`. Haskell and C++ together are 6.9 MB per architecture. `LatexPreview` calls `MathImage(latex:fontSize:…)` without a font (`Sources/OrgPresentation/LatexPreview.swift:99`), so it uses SwiftMath's default and the other eleven fonts, about 6.3 MB per copy, are never loaded. | |
| 261 | ||
| 262 | ### 4.3 Code linked into extensions that don't need it | |
| 263 | ||
| 264 | The widget sources use `AgendaSnapshot`, `HabitSnapshot`, `ClockSnapshot`, `CaptureInbox`, `ProAccess` and three intents; the share extension uses `CaptureInbox` and its template list. Both declare `OrgApp` as their dependency (`Package.swift`, and `packageProductDependencies` in `ios/Orgstar.xcodeproj/project.pbxproj`), which brings `OrgCore`, `OrgIndex` with GRDB, `OrgDocument`, `OrgPresentation` with SwiftMath and its font bundle, and `OrgApp`'s own WebKit, JavaScriptCore, PDFKit, StoreKit, Charts and EventKit code. The watch targets show the alternative: they depend on `OrgWatchData`, 197 lines, and come to 0.74 MB. | |
| 265 | ||
| 266 | Quick Look needs `HTMLExport` and Spotlight needs `FileSummary`. They link the one `OrgCore` module, 57,321 lines, which also holds the commands, agenda, Calc, Babel, keymaps, the Elisp reader and OpenPGP. | |
| 267 | ||
| 268 | ### 4.4 Build time | |
| 269 | ||
| 270 | | | Time | Notes | | |
| 271 | |---|---|---| | |
| 272 | | `swift test`, clean checkout | 164 s | 33 s resolving packages from the local cache, 49 s building, 82 s of tests | | |
| 273 | | `swift test`, nothing to build | 91 s | | | |
| 274 | | `ORGSTAR_SKIP_ORACLE=1 swift test` | 30 s | 252 tests skipped | | |
| 275 | | `swift test --enable-code-coverage` | 143 s | rebuild with instrumentation, then the tests | | |
| 276 | | Release build of all test targets, for the gates | about 3.5 min | | | |
| 277 | | `xcodebuild`, `Orgstar macOS`, clean | 251 s | Release, arm64 + x86_64 | | |
| 278 | | `xcodebuild`, `Orgstar iOS`, clean | 210 s | Release, simulator, arm64 + x86_64, watch app included | | |
| 279 | | `scripts/build-app.sh` | 205 s | release, four products, with part of the release build already cached | | |
| 280 | | `swift build --build-tests`, no change | 3.2 s | | | |
| 281 | | The same after touching one file in `Sources/Orgstar` | 5.4 s | | | |
| 282 | | The same after touching one file in `Sources/OrgCore` | 6.0 s | a change to a declaration other modules use rebuilds them all; not measured | | |
| 283 | ||
| 284 | Disk: `.build` is 3.3 GB after a debug `swift test`, 12 GB after both Xcode builds as well (`.build/xcode` is 6.0 GB), and 14 GB after the release, coverage and app builds of this review. | |
| 285 | ||
| 286 | ## 5. Code quality | |
| 287 | ||
| 288 | ### 5.1 Module boundaries | |
| 289 | ||
| 290 | | Module | Lines | Imports beyond Foundation | | |
| 291 | |---|---|---| | |
| 292 | | `OrgCore` | 57,321 | CryptoKit, CommonCrypto (OpenPGP), ImageIO (ODT image sizes) | | |
| 293 | | `OrgDocument` | 719 | `OrgCore`, CryptoKit | | |
| 294 | | `OrgIndex` | 895 | `OrgCore`, GRDB, CryptoKit | | |
| 295 | | `OrgWorkspace` | 428 | `OrgCore`, `OrgIndex`, CoreServices (FSEvents, behind `#if os(macOS)`) | | |
| 296 | | `OrgPresentation` | 2,338 | `OrgCore`, SwiftMath, AppKit or UIKit in `LatexPreview.swift` only | | |
| 297 | | `OrgApp` | 15,390 | SwiftUI, Observation, AppKit and UIKit, WebKit, JavaScriptCore, PDFKit, StoreKit, EventKit, Charts, ActivityKit, AppIntents, UserNotifications, LocalAuthentication, SQLite3 | | |
| 298 | | `OrgEditorAppKit` | 3,791 | AppKit | | |
| 299 | | `OrgHighlight` | 2,526 | SwiftTreeSitter and 18 grammars | | |
| 300 | | `OrgPrograms` | 642 | `OrgApp` | | |
| 301 | | `OrgWatchData` | 197 | none | | |
| 302 | ||
| 303 | The lower modules are clean: eight platform conditionals in all of `OrgCore`, `OrgDocument`, `OrgIndex`, `OrgWorkspace` and `OrgPresentation` (`Paths.swift:8`, `Sandbox.swift:11,21,38`, `LatexPreview.swift:5,81,109`, `FSEventsWatcher.swift:1`), and no process spawning outside `OrgPrograms`. Nothing platform-specific has leaked downward. | |
| 304 | ||
| 305 | Two boundaries are too coarse. `OrgCore` is one module for everything that is pure Org, which is why the two smallest extensions link 5 MB of it and why any change to one of its declarations rebuilds everything. `OrgApp` mixes models, SwiftUI views, StoreKit and the widget data types, which is why the widget and share extensions link all of it (4.3); it has 46 `#if` blocks. | |
| 306 | ||
| 307 | ### 5.2 Mac and iOS duplication | |
| 308 | ||
| 309 | Identical lines of 40 characters or more, comments and imports left out: | |
| 310 | ||
| 311 | - iOS app against `OrgEditorAppKit`: 236 of 3,268. `MobileEditor+Modal.swift` shares 50 of its 101 lines with `Modal.swift`, `MobileEditor+Latex.swift` 19 of 26 with `OrgEditor+Latex.swift`, `MobileEditor+Display.swift` 36 of 77 with `OrgEditor+Images.swift` and `OrgEditor+Shrink.swift`, `MobileEditor+Styling.swift` 31 of 113, `MobileFragments.swift` 29 of 109 with `Fragments.swift`, `MobileTheme.swift` 22 of 69 with `Theme.swift`. | |
| 312 | - iOS app against the Mac app: 311 of 3,268. `BoardScreen.swift` shares 40 of 81 lines with `BoardView.swift`, `VersionScreens.swift` 28 of 41 with `VersionViews.swift`, `CaptureScreen.swift` 26 of 140, `ProScreen.swift` 17 of 50 with `StoreViews.swift`. `FocusFilter.swift` exists twice and differs in three lines; `CaptureIntent.swift` exists twice and differs in how it reaches the models. | |
| 313 | ||
| 314 | The two editors are the costly pair. They are written separately on the same `Presentation` functions, they have already diverged (the Mac styles in chunks, iOS does not; the Mac guards LaTeX previews with `isOrg`, iOS does not: `OrgEditor+Latex.swift:25`, `MobileEditor+Latex.swift:25`), and only the Mac one has tests. The loop that turns style runs into attribute changes is the part that could live in `OrgPresentation` for both. | |
| 315 | ||
| 316 | ### 5.3 Dead code | |
| 317 | ||
| 318 | Declarations nothing in `Sources/` uses, each checked by search: | |
| 319 | ||
| 320 | - `Days.timeRegex` (`Sources/OrgCore/Agenda/Days.swift:62`) | |
| 321 | - `ClockHistory.defaultLength` (`Sources/OrgCore/Commands/ClockHistory.swift:54`) | |
| 322 | - `sendItem` (`Sources/OrgCore/Commands/OrgList.swift:647`) | |
| 323 | - `resultKeyword` (`Sources/OrgCore/Compute/BabelResults.swift:299`) | |
| 324 | - `TableModel.columnCount` (`Sources/OrgCore/Semantic/TableModel.swift:18`) | |
| 325 | - Used by tests only: `Habit.insertGraph` (`Habit.swift:182`), `Vim.deletedBackward` (`Vim.swift:177`), `IndexStore.duplicateIDs` (`IndexStore.swift:525`), `Presentation.startupWrapperFolds` (`Folding.swift:162`), `AgendaScope` (`Discovery.swift:145`), `DocumentState.canUndo` and `canRedo` (`DocumentState.swift:51-52`). | |
| 326 | ||
| 327 | `OrgstarSpike` (`Sources/OrgstarSpike/main.swift`, 89 lines) is the phase 1 throwaway app. It is still a product in `Package.swift`, so every `swift build` compiles and links it, and `Tests/OrgEditorAppKitTests/TwoViewsSpikeTests.swift` keeps its name alive. | |
| 328 | ||
| 329 | Settings: all 134 entries of `UserConfig.settings` are read somewhere. Commands: every registered command is reachable from the palette, so none is unused in the strict sense; which ones nobody can find is #135 and #138. | |
| 330 | ||
| 331 | The index's unread tables and columns (2.4) are dead data. | |
| 332 | ||
| 333 | ### 5.4 Concurrency | |
| 334 | ||
| 335 | The package builds in the Swift 6 language mode (tools 6.2; the Xcode targets set `SWIFT_VERSION = 6.0`), so data-race checking is on and there are no concurrency warnings. The escape hatches: | |
| 336 | ||
| 337 | - 29 `@unchecked Sendable` types. Most guard their state with a lock (`HiddenRanges`, `FoldedHeadings`, `TextCache`, `FolderPresenter`, `BabelSessions`) or are TextKit subclasses that must be marked. | |
| 338 | - 17 `nonisolated(unsafe)` variables. One is lock-guarded (`EmacsBuffer.cache`, `Sources/OrgCore/Commands/EmacsBuffer.swift:394`). The rest are plain mutable statics. `Theme.blockBackground`, `Theme.selection` and `Theme.focusedLayouts` (`Sources/OrgEditorAppKit/Theme.swift:73-77`) are written on the main actor and, by their own comments, read by layout fragments off it, with no lock; `focusedLayouts` is a `Set`. `UserConfig.directoryOverride` (`Sources/OrgApp/UserConfig.swift:12`) is reassigned on every config reload on iOS (`Sources/OrgstarMobile/MobileModel.swift:127`) while detached tasks read config paths. `AgendaSnapshot.useGroupContainer`, `PDFExport.mathJaxURL`, `DiagramBlocks.vizURL` and `mermaidURL`, `EmacsFallback.offered` and the `TableBlocks` and `RemoteTables` hooks are set once at launch. | |
| 339 | - About 85 unstructured `Task { }` in the app targets and `OrgApp` (25 in `Orgstar`, 41 in `OrgstarMobile`, 17 in `OrgApp`) and 12 `Task.detached`. Most belong to a view's `.task` or are stored and cancelled (`autosave`, `outlineUpdates`, `refreshing`). The Mac's `CaptureIntent` polls for its environment 50 times at 100 ms (`Sources/Orgstar/CaptureIntent.swift:30`). | |
| 340 | ||
| 341 | `WorkspaceRoot.resolve()` calls `startAccessingSecurityScopedResource()` and nothing calls the matching stop (`Sources/OrgWorkspace/Discovery.swift:22`). It runs for every root at launch and on every add, remove and re-grant, and from `savedRootPaths` (`Sources/OrgApp/WorkspaceModel.swift:86`, `:115`, `:140`), so each call leaks one sandbox extension until the app quits. | |
| 342 | ||
| 343 | ### 5.5 Error handling on paths that touch user files | |
| 344 | ||
| 345 | `try?` appears 438 times in `Sources/` (170 in `OrgApp`, 132 in `OrgCore`, 56 in `OrgstarMobile`, 38 in `Orgstar`). `try!` appears 148 times, all but seven on regex patterns; the seven are preset keymaps, two `backToHeading()` calls after a check, a JSON encode of a string, and undo and redo (`DocumentState.swift:74`, `:80`). The document save path itself is strict: `Saver` and `CoordinatedFileSystem` throw, and `DocumentSession` reports through `lastError`. | |
| 346 | ||
| 347 | The exceptions that can lose or hide something: | |
| 348 | ||
| 349 | 1. Shared captures on iOS. `CaptureInbox.take()` deletes each `.link` file as it reads it, whether or not the read worked (`Sources/OrgApp/CaptureInbox.swift:40-47`), and the app keeps what it read in a `@State` queue shown one capture sheet at a time (`Sources/OrgstarMobile/OrgstarMobileApp.swift:373-381`). Captures still in the queue when the app is ended are gone. `AttachmentInbox` does it the right way: the batch stays until `remove`. | |
| 350 | 2. Configuration files read as empty and written back. `MobileModel.set` reads `config.toml` with `(try? String(contentsOf:)) ?? ""` inside the coordinated write and writes the result (`Sources/OrgstarMobile/MobileModel.swift:189-190`); a file that exists but cannot be read (not UTF-8, not downloaded, permission) is replaced by one holding the single setting. The same pattern is in `AgendaViews.save` for `views.toml` (`Sources/OrgApp/AgendaViews.swift:254`) and in the Emacs import for `capture.toml`, `views.toml`, `config.toml` and `keymap.toml` (`Sources/OrgApp/EmacsImport.swift:1197`, `:1210`, `:1223`, `:1236`, `:1270`). | |
| 351 | 3. Writes whose failure nobody sees: `MobileModel.saveConfig` (`MobileModel.swift:176`, which also drops the coordinator's error), `ConfigSync` (`Sources/OrgApp/ConfigSync.swift:57`, `:63`, `:169`), every write of the Emacs import (`EmacsImport.swift:1207`, `:1220`, `:1233`, `:1250`, `:1282`) while its summary still counts the items as imported, the clock report's Save (`Sources/Orgstar/ClockViews.swift:262`), `TrustStore.save` (`Sources/OrgApp/TrustStore.swift:27`) and `ClockModel`'s state file (`Sources/OrgApp/ClockModel.swift:76`). | |
| 352 | 4. Index failures shown as nothing. `filesChanged` drops reconcile errors (`Sources/OrgApp/WorkspaceModel.swift:289`, `:295`, `:298`) where `refreshOnce` reports them; `search`, `nodes` and `backlinks` return an empty list on any database error (`:447`, `:460`, `:464`). | |
| 353 | 5. `DocumentSession.fileChanged` returns silently when the changed file cannot be read (`Sources/OrgApp/DocumentSession.swift:1086`), so the buffer stays on the old text with no message. | |
| 354 | ||
| 355 | Force unwraps: four `as!` and five `fatalError` or `precondition` calls, none on a file path. | |
| 356 | ||
| 357 | ### 5.6 Tests | |
| 358 | ||
| 359 | Line coverage from `swift test --enable-code-coverage`, merged over the ten test bundles: | |
| 360 | ||
| 361 | | Module | Lines | Covered | Tests | | |
| 362 | |---|---|---|---| | |
| 363 | | `OrgCore` | 52,761 | 94.6 % | 542 | | |
| 364 | | `OrgApp` | 12,684 | 75.2 % | 304 | | |
| 365 | | `OrgEditorAppKit` | 3,188 | 77.4 % | 118 | | |
| 366 | | `OrgPresentation` | 1,771 | 97.2 % | 72 | | |
| 367 | | `OrgIndex` | 1,121 | 95.6 % | 14 | | |
| 368 | | `OrgPrograms` | 599 | 85.0 % | 31 | | |
| 369 | | `OrgDocument` | 565 | 98.1 % | 40 | | |
| 370 | | `OrgWorkspace` | 360 | 91.1 % | 17 | | |
| 371 | | `OrgWatchData` | 126 | 92.9 % | 3 | | |
| 372 | | `OrgHighlight` | 92 executable | 100 % | 7 | | |
| 373 | | `Orgstar` (Mac app), 8,869 source lines | | none | 0 | | |
| 374 | | `OrgstarMobile` (iOS app), 10,278 source lines | | none | 0 | | |
| 375 | | Widgets, share, watch, Quick Look, Spotlight, 1,308 source lines | | none | 0 | | |
| 376 | ||
| 377 | The gaps in `OrgApp` are whole files: `AttachActions.swift` 2 %, `RoamGraphView.swift`, `CryptSheet.swift`, `EmacsImportSections.swift`, `EventSheet.swift` and `DiffView.swift` 0 %, `ProStore.swift` 7 %. The app targets have no test target, which leaves the iOS editor (about 2,150 lines in `MobileEditor*.swift` and `MobileFragments.swift`) with none. | |
| 378 | ||
| 379 | The suite is not deterministic. `CalcTests.symbolicFunctionsMatchCalc` picks a random seed unless `ORGSTAR_SEED` is set (`Tests/OrgCoreTests/CalcTests.swift:451`), and four more Calc tests, `LineIndexTests` and `ListItemScanTests` use `SystemRandomNumberGenerator` (`CalcTests.swift:272`, `:297`, `:314`, `:402`; `LineIndexTests.swift:14`, `:37`; `ListItemScanTests.swift:11`). One of four full runs during this review failed: | |
| 380 | ||
| 381 | ``` | |
| 382 | abs(vmin([(3 - uinf) ^ (-1)], [0. < (-1 > 2.5)])) (eng 2) p12 seed 13596949266880706848 | |
| 383 | ours "0", expected "nan" | |
| 384 | ``` | |
| 385 | ||
| 386 | That is a real difference from Emacs Calc, and it is also a suite that can fail an unrelated merge request. | |
| 387 | ||
| 388 | Emacs. With `ORGSTAR_SKIP_ORACLE=1`, 252 of 1,148 tests are skipped and the run drops from 91 s to 30 s. Without the variable and without Emacs the oracle tests fail rather than skip, as the October review recorded; that was not tried again here. Skipped silently on a machine that lacks the tool: the Babel tests for `ruby`, `node`, `gcc` and `python3`, the Denote tests without the `denote` packages, and two tests that read the developer's own files (`Tests/OrgAppTests/EmacsImportTests.swift:385` reads `~/.config/doom/config.el`; `Tests/OrgCoreTests/LispReaderTests.swift:27` reads `~/.config/emacs/lisp`). Ten corpus tests need `ORGSTAR_ORACLE_CORPUS` and never run by default. | |
| 389 | ||
| 390 | Slow tests: the slowest suite is `OrgCoreTests` at 55 to 60 s of wall time, nearly all of it waiting on `emacs --batch`; the slowest single tests are `searchMatchesEmacs` (55 s), `regionFillMatchesEmacs` (45 s) and `listsSortLikeOrg` (42 s). Without the oracle no test takes over 12 s. | |
| 391 | ||
| 392 | Litter: tests create `UserDefaults` suites named with a fresh UUID and only 13 call sites remove the domain. Each `swift test` leaves 33 plist files in `~/Library/Preferences`. This Mac has 12,396 `orgstar-*-<UUID>.plist` files there (5,675 `orgstar-config-…`, 1,177 `orgstar-import-…`, 1,143 `orgstar-theme-…` and thirteen more families), and the `test.<UUID>` and `hidden-<UUID>` suites that `ProAccessTests`, `WhatsNewTests` and `AppTests` create add to the 1,859 files of those two patterns; together about 17 MB. | |
| 393 | ||
| 394 | ### 5.7 Compiler warnings | |
| 395 | ||
| 396 | `swift test` prints eight distinct warnings; the Mac App Store build prints the six that are in app sources; the iOS build prints none. | |
| 397 | ||
| 398 | - `Sources/Orgstar/BufferTabs.swift:35`, `Sidebar.swift:18`, `:144`, `:175`: `ThemeSpec` used in a property without importing `OrgPresentation`. | |
| 399 | - `Sources/Orgstar/ColumnViewSheet.swift:178`: `??` on a non-optional `String`. | |
| 400 | - `Sources/Orgstar/ContentView.swift:332`: `weak` captures of `session`, `clock` and `commands` that are captured strongly by the enclosing closure. | |
| 401 | - `Sources/Orgstar/ContentView.swift:919`: `attachActions` read inside its own getter. The read is in a closure that runs later, so it does not recurse. | |
| 402 | - `Tests/OrgAppTests/EmacsImportTests.swift:349`: `await` with nothing asynchronous. | |
| 403 | - `Tests/OrgEditorAppKitTests/EditorTests.swift:307`: a downcast that does nothing. | |
| 404 | ||
| 405 | `appintentsmetadataprocessor` also warns that the Quick Look and Spotlight targets have no App Intents, which is correct. Code scanning findings are #109. | |
| 406 | ||
| 407 | ## 6. What holds up | |
| 408 | ||
| 409 | - Parsing is linear to 10 MB: 85 ms per MB on the synthetic document. October measured 40 and 74 ms per MB on two real files. | |
| 410 | - Typing in files up to 1.5 MB stays under the 16 ms gate (4.5 to 11.5 ms p95). | |
| 411 | - Index queries are fast enough at 10,000 files, and a single changed file costs 20 ms. | |
| 412 | - The save sequence costs 7 ms per MB and reports every failure. | |
| 413 | - The widgets and the watch app read snapshots and do no parsing of their own. | |
| 414 | - Module boundaries below `OrgApp` hold, as the October review found. | |
| 415 | - Dead code is rare: eleven declarations in 105,000 lines. | |
| 416 | ||
| 417 | ## 7. Needs a device, Instruments, or a setup this review did not have | |
| 418 | ||
| 419 | Test files, 1 MB and 10 MB: | |
| 420 | ||
| 421 | ```sh | |
| 422 | for size in 1000000 10000000; do | |
| 423 | awk -v max=$size 'BEGIN { while (n < max) { s = sprintf("* TODO Project %d :work:\nSCHEDULED: <2026-11-21 Sat>\n** Section\nParagraph with *bold*, /italic/, =code= and a [[https://example.com/%d][link]].\n\n- item one\n- item two [ ]\n\n", i, i); printf "%s", s; n += length(s); i++ } }' > big-$size.org | |
| 424 | done | |
| 425 | ``` | |
| 426 | ||
| 427 | The `Orgstar iOS` and `Orgstar macOS` schemes run the Release configuration with `ORGSTAR_PERF` set, so the app logs to subsystem `sh.krz.orgstar`, category `perf`: every measured interval over 16 ms (`session.open`, `session.save`, `session.fileChanged`, `editor.restyleAll`, `editor.restyle`, `editor.edit`, `agenda.refresh`, `agenda.sources`, `workspace.refresh`, `widgets.update`, `reminders.update`, `spotlight.update`) and every main-thread wait of 100 ms or more. Read it in Console.app with the device selected and the filter `subsystem:sh.krz.orgstar category:perf`. | |
| 428 | ||
| 429 | 1. iPhone and iPad launch, cold and warm. Xcode ▸ Product ▸ Profile on the `Orgstar iOS` scheme, App Launch template. Cold: restart the device, wait a minute, record. Warm: end the app from the switcher and record again. Read "time to first frame" and, for the first editable frame, the end of the first `session.open` interval in the signpost track. | |
| 430 | 2. iOS editor with large files. Put the two files in a folder the app has, open each, and read `session.open took`, `editor.restyleAll took` and `main thread blocked for` in Console. Type 20 characters in the middle of the 1 MB file and read `editor.edit took` and `editor.restyle took`. Expect the 10 MB file to be ended by the watchdog; note whether it is. | |
| 431 | 3. iOS memory. With the 1 MB file open three times over (three copies), read the memory gauge in Xcode's debug navigator, then open the 10 MB file and note the footprint or the termination. Product ▸ Profile, Leaks template, for ten minutes of editing, switching files and opening the agenda. | |
| 432 | 4. Widgets. Add the Today, Up Next and Habits widgets. Debug ▸ Attach to Process ▸ `OrgstarWidgets`, edit an entry in the app, and read the extension's memory at the timeline reload. Filter Console for `widgets.update took` in the app. | |
| 433 | 5. Watch app and complications. Run the `OrgstarWatch` target on a watch, send an agenda from the phone by editing an entry, and read the memory gauge and the time from the edit to the watch's list changing. | |
| 434 | 6. Live Activity. Clock in, lock the phone for 30 minutes, and read Settings ▸ Battery for orgstar's share; in Instruments, the Activity Monitor template attached to the widgets extension shows its CPU while the activity runs. | |
| 435 | 7. Energy. Product ▸ Profile, Power Profiler (or the energy gauge), for five minutes idle with a folder of a few hundred files, then five minutes of typing. On the Mac, the same with the app in the background, to see the mode line's 5-second timer. | |
| 436 | 8. Sync folders. Put a 1 MB file in iCloud Drive and in a Syncthing folder (Möbius Sync on iOS), edit it for a minute with autosave on, change it from a second device, and read `session.save took` and `session.fileChanged took` on both platforms. Repeat on the Mac with the file evicted (Remove Download) before opening it. | |
| 437 | 9. Mac cold launch. Restart, wait a minute, launch once from the Dock, and read the first `main thread blocked` lines and the time to the window; or Product ▸ Profile, App Launch, on `Orgstar macOS`. | |
| 438 | 10. Hangs and retain cycles in a long session. Instruments, Hangs and Leaks templates, on the Mac app with the 1,000-file folder: open ten files, split panes, open and close the agenda and the board five times, and check that `OrgEditor`, `DocumentSession.Entry` and `AgendaModel` counts in Allocations return to their starting values. | |
| 439 | 11. Download sizes. Archive both schemes (`ORGSTAR_PUBLISH=0 scripts/release-ios.sh` and `scripts/release-macos.sh`) and read App Store Connect ▸ TestFlight ▸ build ▸ App File Sizes for the thinned sizes per device. | |
| 440 | 12. The M1 Air gate run, issue 2: `ORGSTAR_GATES=1 swift test -c release --filter GateTests`. | |
| 441 | ||
| 442 | ## 8. Not covered, and why | |
| 443 | ||
| 444 | - Highlighting and folding as separate timings: the gates include both, and no existing benchmark splits them. | |
| 445 | - PDF, Word and RTF export: they need WebKit and a window server session, and were left for a profile in the app. | |
| 446 | - LaTeX, ASCII and ODT export above 300 kB, and every export at 10 MB: the ASCII export made the runs too long to finish, and the others were not timed apart from it. | |
| 447 | - The 154 to 318 ms waits at every launch: seen in the log, not profiled. | |
| 448 | - The superlinear growth of the day view with tens of thousands of items, and of ASCII export without footnotes: measured, not profiled. | |
| 449 | - Rebuild time after a change to an `OrgCore` declaration: it needs a source edit, which this review does not make. | |
| 450 | - Anything on iCloud Drive or Syncthing, and everything in section 7. | |
| 451 | ||
| 452 | ## 9. Findings worth fixing | |
| 453 | ||
| 454 | Severity is high (data loss, or seconds of blocked UI in ordinary use), medium (visible cost at sizes people have, or a structural cost paid on every build or download), or low. | |
| 455 | ||
| 456 | 1. **High. The editor styles the whole file before the first frame.** Open takes 560 ms for 1 MB against a 100 ms gate; all four gate files fail on open (2.1). `Sources/OrgEditorAppKit/OrgEditor.swift:125`. Fix: remove the whole-file restyle from `init` and let the chunked styling pick up `indented` and `hideStars`, which are known before `load` runs. | |
| 457 | 2. **High. The backlinks pane blocks the main thread after every pause in typing.** 1.6 to 9.8 s with 49,400 links; about 0.3 s per 5,000 links (2.3). `Sources/Orgstar/BacklinksPane.swift:35`, `:59-77`; `Sources/OrgApp/WorkspaceModel.swift:445-456`; `Sources/OrgCore/Links/Backlinks.swift:24`, `:45`; `Sources/OrgCore/Links/Links.swift:38`. Fix: hoist the two regular expressions into statics, compute off the main actor, and recompute only when the file, the heading or the index changes rather than on each edit. | |
| 458 | 3. **High. Styling cost grows with the square of the file size.** 1.17 s for 1 MB, 129 s for 10 MB, 77 ms per key at 10 MB (2.2). `Sources/OrgEditorAppKit/OrgEditor+Styling.swift:19-57` and its iOS copy. Fix: merge paragraph style and role attributes into one ascending pass so run insertions append instead of shifting the tail, and check the result with the gates; for edits inside very large files that still leaves a tail shift per insertion, so decide whether 10 MB is a supported size and, if it is, back the storage with a structure whose insertions are not linear. | |
| 459 | 4. **High. The iOS editor styles the whole file synchronously at load, and on every edit under 60,000 units.** At least the Mac's 1.17 s per MB on the main thread; not measured on a device. `Sources/OrgstarMobile/MobileEditor+Styling.swift:12-18`, `:99-105`, `:166`. Fix: share the Mac editor's watermark and chunked styling, ideally by moving the run-to-attribute loop into `OrgPresentation` for both. | |
| 460 | 5. **High. Shared captures on iOS are deleted before they are filed.** `Sources/OrgApp/CaptureInbox.swift:40-47`, `Sources/OrgstarMobile/OrgstarMobileApp.swift:373-381`. Fix: list the links without removing them and remove each when its capture sheet is saved or discarded, as `AttachmentInbox` does. | |
| 461 | 6. **High. Configuration writers replace a file they could not read, and hide failed writes.** `Sources/OrgstarMobile/MobileModel.swift:176`, `:189-190`; `Sources/OrgApp/AgendaViews.swift:254`; `Sources/OrgApp/EmacsImport.swift:1197-1282`; `Sources/OrgApp/ConfigSync.swift:57`, `:63`, `:169`; `Sources/Orgstar/ClockViews.swift:262`. Fix: treat only "no such file" as empty, stop on any other read error, and report write errors where the action started. | |
| 462 | 7. **Medium. The performance gates run nowhere.** The regression in finding 1 is six weeks old (2.1). Fix: run the gates from the three release scripts and fail the release on a miss; add a 10 MB case and budgets for index build, agenda refresh and backlinks. | |
| 463 | 8. **Medium. The inspector pane recomputes while hidden.** 362 ms on the main thread per pause for a 1 MB file. `Sources/Orgstar/InspectorPane.swift:44`, `:143`. Fix: run the task only while `inspectorShown`, and build the column view and clock report off the main actor. | |
| 464 | 9. **Medium. TAB in a table realigns the whole table.** 63 ms at 500 rows, 616 ms at 5,000 (2.6). `Sources/OrgCore/Commands/Table.swift:289-293`. Fix: realign only when the field left behind changed width, as `org-table-may-need-update` does. | |
| 465 | 10. **Medium. Every agenda refresh stats every agenda file on the main actor.** 50 ms per 1,000 files; 502 ms at 10,000 (2.5). `Sources/OrgApp/AgendaModel.swift:187-202`. Fix: move the stat loop into the detached task and invalidate cache entries from the workspace's file events instead. | |
| 466 | 11. **Medium. Each agenda model keeps its own parsed copy of every agenda file.** Five caches on the Mac, 176 MB and 7.5 s each at 10,000 files (2.5). `Sources/Orgstar/AgendaView.swift:111`, `BoardView.swift:33`, `AgendaSidebar.swift:34`, `ContentView.swift:1176`, `:1191`; `Sources/OrgstarMobile/BoardScreen.swift:28`. Fix: one `AgendaSourceCache` owned by the workspace and passed to every model. | |
| 467 | 12. **Medium. Opening, saving and reloading a file do coordinated I/O on the main actor.** 7 ms per MB locally; unbounded on a File Provider (2.7). `Sources/OrgApp/DocumentSession.swift:253`, `:444`, `:1083`. Fix: do the read, merge check and replace on a background task and apply the outcome on the main actor. | |
| 468 | 13. **Medium. An edit in a file with any non-ASCII character costs 3.3 ms per MB in the document model.** 33.5 ms at 10 MB (2.2). `Sources/OrgDocument/DocumentState.swift:85-105`, `:178-182`. Fix: keep the text in a form with constant-time UTF-16 offsets, or carry UTF-8 offsets in `TextEdit` so no index conversion is needed. | |
| 469 | 14. **Medium. The index is built in one transaction on a queue that blocks readers.** 11.8 s and 249 MB for 10,000 files, with search and the file list waiting (2.4). `Sources/OrgWorkspace/Reconciler.swift:69-130`, `Sources/OrgIndex/IndexStore.swift:76-80`, `:201-218`. Fix: commit in batches of a few hundred files, open the store as a `DatabasePool` in WAL mode, and parse files concurrently. | |
| 470 | 15. **Medium. Search and backlinks rebuild the dirty buffer's index record on the main actor.** 212 ms per MB each time the text changed (2.3). `Sources/OrgApp/WorkspaceModel.swift:479-488`, `Sources/Orgstar/ContentView.swift:276`, `Sources/OrgstarMobile/SearchScreen.swift:26`. Fix: build the overlay from the buffer's existing tree off the main actor, and take the search call out of `body`. | |
| 471 | 16. **Medium. Memory per open file exceeds two gate limits.** 50.7x for the table (limit 45x), 11.6x for `csg.org` (limit 10x), 352 MB for a 10 MB file (section 3). Fix: the compact tree the performance plan already describes (token text as offsets), and compare against a hash of the saved text instead of keeping a second copy of it. | |
| 472 | 17. **Medium. The widget and share extensions link all of `OrgApp`.** 45 MB each as built, 9.7 MB of `__TEXT` per architecture, with a 7.1 MB font bundle (4.1, 4.3). `Package.swift`, `ios/Orgstar.xcodeproj/project.pbxproj`. Fix: move the snapshot types, `CaptureInbox` and the widget intents into a Foundation-only module, as `OrgWatchData` is, and make it the extensions' only dependency. | |
| 473 | 18. **Medium. The test suite is not deterministic, and one random case differs from Emacs Calc.** `Tests/OrgCoreTests/CalcTests.swift:451` and the unseeded generators listed in 5.6; seed 13596949266880706848. Fix: fixed default seeds with a variable for random runs, and fix or refuse `abs(vmin([(3 - uinf) ^ (-1)], [0. < (-1 > 2.5)]))`, where orgstar answers `0` and Calc `nan`. | |
| 474 | 19. **Medium. The iOS app has no tests, and its editor duplicates the Mac's.** 10,278 lines at 0 % coverage; 236 identical lines between the two editors (5.2, 5.6). Fix: move the styling driver and the modal-key glue into shared modules where the Mac's tests cover them, and merge `FocusFilter.swift` and `CaptureIntent.swift` into one file each. | |
| 475 | 20. **Low. ASCII export is quadratic, and exporters parse their regexes on every use.** 1.65 s for 100 kB, 12.8 s for 300 kB (2.8). `Sources/OrgCore/Export/ASCIIExport.swift:1369-1370`; 197 inline regex literals in `OrgCore`. Fix: collect footnote definitions once, as the ODT and Markdown exporters do, and move regex literals on hot paths into `static let`. | |
| 476 | 21. **Low. The Developer ID binaries ship unstripped.** 22.7 MB of 102 MB per architecture (4.1). `scripts/build-app.sh`. Fix: `strip -x` each executable before signing and keep the dSYMs with the release. | |
| 477 | 22. **Low. Eleven of SwiftMath's twelve fonts are never used.** 6.3 MB per copy, two copies on the Mac and three on iOS (4.2). Fix: delete the unused fonts from the bundle in `scripts/build-app.sh` and in a build phase of the Xcode targets; finding 17 removes the extra copies. | |
| 478 | 23. **Low. The iOS asset catalog is 18 MB of alternate app icons.** 13 sets at up to 2.1 MB (4.2). `ios/Orgstar/Assets.xcassets`. Fix: recompress the artwork or offer fewer icons. | |
| 479 | 24. **Low. Quick Look and Spotlight link all of `OrgCore`.** 16 MB each, universal (4.1). Fix: split the parser, `FileSummary` and the HTML exporter from commands, agenda, Calc, Babel and keymaps, which also shortens rebuilds after a change to the upper half. | |
| 480 | 25. **Low. The index stores data nothing reads.** Three tables, the inherited tag rows and five columns; 5.4 MB of 62 MB here (2.4). `Sources/OrgIndex/IndexStore.swift:118-146`, `:248-266`. Fix: stop writing them in a migration, or move the agenda onto them. | |
| 481 | 26. **Low. A whole-root scan costs a second per 10,000 files with nothing changed.** It runs at launch and after trashing or renaming (2.4). `Sources/OrgWorkspace/Discovery.swift:109-138`, `Sources/OrgApp/WorkspaceModel.swift:430-435`. Fix: reconcile the affected paths after a trash or rename instead of the root, and read sizes and dates in bulk. | |
| 482 | 27. **Low. A month view scans every source 30 times.** 796 ms at 10,000 files with few dated entries (2.5). `Sources/OrgCore/Agenda/Agenda.swift:192-199`. Fix: collect each source's dated entries once and distribute them over the days. | |
| 483 | 28. **Low. Index errors are shown as empty results.** `Sources/OrgApp/WorkspaceModel.swift:289`, `:295`, `:298`, `:447`, `:460`, `:464`; `Sources/OrgApp/DocumentSession.swift:1086`. Fix: set `lastError` as `refreshOnce` does. | |
| 484 | 29. **Low. Tests leave preference files behind.** 33 per run; 12,396 on this Mac (5.6). Fix: remove each suite's persistent domain when the test ends, in one helper the tests share. | |
| 485 | 30. **Low. Energy: polling and redundant reloads.** `Sources/Orgstar/ModeLine.swift:105-112` reads `.git/HEAD` every 5 s; `Sources/OrgstarMobile/MobileModel.swift:301-306` reloads all widget timelines on every update while locked; `Sources/Orgstar/ContentView.swift:1168-1173` refreshes the widgets' agenda after every pause when reminders are off. Fix: poll only while the window is key, reload timelines only when the locked state changed, and give the widget refresh the reminders' two-second delay. | |
| 486 | 31. **Low. The iOS Spotlight indexer holds every changed file in memory.** `Sources/OrgstarMobile/SpotlightIndexer.swift:56-76`. Fix: read and submit in batches of about a hundred files. | |
| 487 | 32. **Low. Unsynchronised statics read off the main actor, and an unbalanced security scope.** `Sources/OrgEditorAppKit/Theme.swift:73-77`, `Sources/OrgApp/UserConfig.swift:12`, `Sources/OrgWorkspace/Discovery.swift:22`. Fix: guard the three `Theme` statics and `directoryOverride` with a lock, and keep the URL from the first `resolve()` instead of starting access again. | |
| 488 | 33. **Low. Dead code and warnings.** The eleven declarations in 5.3, the `OrgstarSpike` product, and the eight warnings in 5.7. Fix: delete, and add the missing `import OrgPresentation`. | |