Style the iOS editor in chunks and restyle only what an edit affects !460

merged merged by cmc on 2026-11-22 18:25 UTC · krz/orgstar:issue-190-ios-styling into main

Discussion

cmc

Closes #190.

  • MobileEditor styles the first 30,000 UTF-16 units at load and the rest in 50,000-unit background passes (the Mac uses 200,000; on the simulator a 200,000-unit pass took 165-230 ms). Markup, spelling, image, LaTeX, theme and settings toggles restart the passes instead of restyling the whole file. Per edit it restyles the region the edit affects, whatever the file size; the 60,000-unit whole-file rule is gone.
  • Moved to OrgPresentation (Restyling.swift) and used by both editors: StyledExtent (watermark), Presentation.styleChanges (indents and roles in one ascending pass, from #189), Presentation.affectedRange, headingLineNear, and restyleRange (old and new affected region of an edit).
  • affectedRange no longer widens to the start of the file when the edited lines span two top-level sections and touch a heading (for example a keyboard replacement across the newline before * Heading). The adjacent sections already cover what changes. In a 10 MB file this made one keystroke restyle half the file (148 s on the simulator). The Mac had the same over-wide range; its output does not change.
  • Tests: Tests/OrgPresentationTests/RestylingTests.swift, including a check that restyling only restyleRange matches restyling the whole text for every insertion and deletion position in a mixed document.

Simulator (iPhone 17, Release, indicative only), awk files from the review:

before after
1 MB open, editor.restyle 1,207-1,283 ms in one block 26 ms, then 20 passes of 40-51 ms
10 MB open, editor.restyle 51,755 ms in one block (90 s main-thread block) first chunk under 300 ms, then 200 passes, median 43 ms, max 295 ms
10 MB typing, editor.edit 16-31 ms 41-75 ms

Not changed here, and the cause of the remaining multi-second main-thread blocks at open and per keystroke: ExportMenu.body calls ExportScope.fileName, which parses the whole document on every evaluation (ExportMenu.swift:188): about 1-4 s per keystroke at 1 MB and 11-12 s at 10 MB on the simulator. The reader blocks the main thread for 25 s when it opens the 10 MB file.