Performance review: code quality, size and speed #96

closed cmc opened this on 2026-11-22 04:25 UTC · milestone 1 Reviews and cleanup

Discussion

cmc 2026-11-22 04:25 UTC

Review the whole codebase (about 105,000 lines of Swift under Sources/ and ios/) and record findings as separate issues.

Speed

  • Launch to first editable frame, Mac and iPhone, cold and warm.
  • Opening and typing in large files (1 MB, 10 MB): parse, incremental reparse, highlighting, folding, table alignment.
  • Index build and rebuild for a large folder (10,000 files); cost of a single-file change.
  • Agenda build for day, week, month and block views; text search and Search Notes latency.
  • Save, external-change detection and conflict checks on iCloud Drive and Syncthing folders.
  • Export (HTML, PDF, LaTeX, ODT, Word) and tangling on long documents.
  • Widgets, the watch app and the Live Activity: timeline reload cost and memory.
  • Re-run the gates in docs/plans/2026-10-04-performance.md and compare with the earlier numbers.

Memory and energy

  • Peak and steady memory with several large buffers open; leaks and retain cycles (Instruments).
  • Background work on iOS: file watching, indexing, notification scheduling.
  • Main-thread hangs over 100 ms.

Size

  • App bundle and download size per target (Mac download, Mac App Store, iOS, watch, extensions).
  • What each bundled resource costs: tree-sitter grammars, MathJax, fonts, themes, string catalogs.
  • Code linked into extensions that don't need it (Quick Look, Spotlight, Share, widgets).
  • Build time, clean and incremental.

Code quality

  • Module boundaries: what OrgCore, OrgDocument, OrgIndex, OrgApp and the app targets depend on, and anything platform-specific that has leaked into shared modules.
  • Duplicate code between the Mac and iOS targets that belongs in a shared module.
  • Dead code, unused commands and settings, stale OrgstarSpike code.
  • Concurrency: actor isolation, @unchecked Sendable, unstructured tasks, data races under Swift 6 strict checking.
  • Error handling: swallowed errors, try? and force unwraps on paths that touch user files.
  • Test coverage by module, slow tests, and tests skipped when Emacs is missing.
  • Compiler warnings and code scanning findings still open.

Output

  • A dated report in docs/ next to review-2026-10-05.md and review-2026-10-13.md, with measurements and the device and OS they were taken on.
  • One issue per finding worth fixing, linked from this one.

referenced in commit 9cf7ae99af by cmc: Add the performance review report

2026-11-22 07:09 UTC
cmc 2026-11-22 07:11 UTC

Issues filed from the performance review, docs/review-2026-11-21.md:

1 Reviews and cleanup

  • #187 Editor styles the whole file before the first frame
  • #188 Backlinks pane blocks the main thread after every pause in typing
  • #189 Styling cost grows with the square of the file size
  • #190 iOS editor styles the whole file synchronously at load and on every edit under 60,000 units
  • #191 Shared captures are deleted from the inbox before they are filed
  • #192 Configuration writers replace a file they could not read and hide failed writes
  • #193 Run the performance gates in the release scripts
  • #194 Inspector pane recomputes while hidden
  • #195 TAB in a table realigns the whole table
  • #196 Agenda refresh stats every agenda file on the main actor
  • #204 Test suite is not deterministic; one random Calc case differs from Emacs
  • #207 Developer ID binaries ship unstripped
  • #208 Eleven of SwiftMath's twelve fonts are never used
  • #209 iOS asset catalog holds 18 MB of alternate app icons
  • #214 Index and reload errors are shown as empty results
  • #215 Tests leave preference files in ~/Library/Preferences
  • #216 Energy: polling and redundant reloads

Backlog

  • #197 Each agenda model keeps its own parsed copy of every agenda file
  • #198 Opening, saving and reloading files do coordinated I/O on the main actor
  • #199 Edits in a file with non-ASCII text cost 3.3 ms per MB in the document model
  • #200 Index build is one transaction on a queue that blocks readers
  • #201 Search and backlinks rebuild the dirty buffer's index record on the main actor
  • #202 Memory per open file exceeds two gate limits
  • #203 Widget and share extensions link all of OrgApp
  • #205 iOS app has no tests and its editor duplicates the Mac's
  • #206 ASCII export is quadratic; exporters re-parse regex literals on every use
  • #210 Quick Look and Spotlight extensions link all of OrgCore
  • #211 Index stores tables and columns nothing reads
  • #212 Whole-root scan costs a second per 10,000 files with nothing changed
  • #213 Month agenda scans every source 30 times
  • #217 iOS Spotlight indexer holds every changed file in memory
  • #218 Unsynchronised statics and an unbalanced security scope
  • #219 Dead code and compiler warnings