# orgstar review, 2026-11-21 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. Facts, for calibration: | | | |---|---| | Version | 1.2.0, commit 1bdd0d3 | | Size | 403 Swift files and 104,801 lines under `Sources/`; `ios/` holds the Xcode project, plists and assets, no Swift | | Tests | 1,148 tests in 10 test targets, 28,772 lines; all pass, with one exception described in 5.6 | | Machine | MacBook Pro Mac14,10, Apple M2 Pro (8 performance and 4 efficiency cores), 16 GB | | Software | macOS 27.0.1 (26A434), Xcode 27.2 (27B52), Swift 6.4.2, Emacs 31.1 | | Power | Low power mode off. The first test run and the Xcode builds ran on battery, the gates and benchmarks on mains | 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. ## 1. Verdict 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. Three things are wrong and affect ordinary use on the Mac today: 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. 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. 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. 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. 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. ## 2. Speed ### 2.1 Gates `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. | File | Measure | 2026-10-04 | Today | Gate | | |---|---|---|---|---|---| | Single 1 MB section | open | 76 ms | 560 ms | 100 ms | fails | | | typing p95 | 7.0 ms | 9.8 ms | 16 ms | | | | blank line p95 | 8.1 ms | 11.1 ms | 16 ms | | | | memory | 30.4x | 38.1x | 45x | | | 5,000-row table (312 kB) | open | 38 ms | 133 ms | 100 ms | fails | | | typing p95 | 3.2 ms | 4.5 ms | 16 ms | | | | blank line p95 | 8.8 ms | 10.0 ms | 16 ms | | | | memory | 42.9x | 50.7x | 45x | fails | | 3,000 entries with drawers (821 kB) | open | | 236 ms | 100 ms | fails | | | typing / blank line p95 | | 9.2 / 9.2 ms | 16 ms | | | | memory | | 24.7x | 45x | | | `csg.org` (1,545 kB) | open | 75 ms | 219 ms | 155 ms | fails | | | typing p95 | 6.5 ms | 11.5 ms | 16 ms | | | | blank line p95 | 7.3 ms | 12.0 ms | 16 ms | | | | memory | 9.6x | 11.6x | 10x | fails | 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`: ```swift if !indented || !hideStars { restyleOutsideEditing(0.. 2.5)])) (eng 2) p12 seed 13596949266880706848 ours "0", expected "nan" ``` That is a real difference from Emacs Calc, and it is also a suite that can fail an unrelated merge request. 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. 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. 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-*-.plist` files there (5,675 `orgstar-config-…`, 1,177 `orgstar-import-…`, 1,143 `orgstar-theme-…` and thirteen more families), and the `test.` and `hidden-` suites that `ProAccessTests`, `WhatsNewTests` and `AppTests` create add to the 1,859 files of those two patterns; together about 17 MB. ### 5.7 Compiler warnings `swift test` prints eight distinct warnings; the Mac App Store build prints the six that are in app sources; the iOS build prints none. - `Sources/Orgstar/BufferTabs.swift:35`, `Sidebar.swift:18`, `:144`, `:175`: `ThemeSpec` used in a property without importing `OrgPresentation`. - `Sources/Orgstar/ColumnViewSheet.swift:178`: `??` on a non-optional `String`. - `Sources/Orgstar/ContentView.swift:332`: `weak` captures of `session`, `clock` and `commands` that are captured strongly by the enclosing closure. - `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. - `Tests/OrgAppTests/EmacsImportTests.swift:349`: `await` with nothing asynchronous. - `Tests/OrgEditorAppKitTests/EditorTests.swift:307`: a downcast that does nothing. `appintentsmetadataprocessor` also warns that the Quick Look and Spotlight targets have no App Intents, which is correct. Code scanning findings are #109. ## 6. What holds up - 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. - Typing in files up to 1.5 MB stays under the 16 ms gate (4.5 to 11.5 ms p95). - Index queries are fast enough at 10,000 files, and a single changed file costs 20 ms. - The save sequence costs 7 ms per MB and reports every failure. - The widgets and the watch app read snapshots and do no parsing of their own. - Module boundaries below `OrgApp` hold, as the October review found. - Dead code is rare: eleven declarations in 105,000 lines. ## 7. Needs a device, Instruments, or a setup this review did not have Test files, 1 MB and 10 MB: ```sh for size in 1000000 10000000; do 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 done ``` 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`. 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. 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. 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. 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. 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. 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. 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. 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. 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`. 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. 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. 12. The M1 Air gate run, issue 2: `ORGSTAR_GATES=1 swift test -c release --filter GateTests`. ## 8. Not covered, and why - Highlighting and folding as separate timings: the gates include both, and no existing benchmark splits them. - PDF, Word and RTF export: they need WebKit and a window server session, and were left for a profile in the app. - 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. - The 154 to 318 ms waits at every launch: seen in the log, not profiled. - The superlinear growth of the day view with tens of thousands of items, and of ASCII export without footnotes: measured, not profiled. - Rebuild time after a change to an `OrgCore` declaration: it needs a source edit, which this review does not make. - Anything on iCloud Drive or Syncthing, and everything in section 7. ## 9. Findings worth fixing 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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`. 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. 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. 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`. 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. 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`. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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`.