Styling cost grows with the square of the file size #189

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

Discussion

cmc 2026-11-22 07:11 UTC

Severity: High.

restyle (Sources/OrgEditorAppKit/OrgEditor+Styling.swift:19-57) adds a paragraph style per line and then applies each role from the start, so every addAttribute shifts the tail of NSTextStorage's run array (2,369 of 3,826 profile samples in NSMutableRLEArray insertObject:range:). Styling takes 6.5 ms for 60 kB, 1.17 s for 1 MB and 129 s for 10 MB; typing p95 in a 10 MB file is 77 ms and opening it takes 18.9 s. Apply paragraph style and role attributes in one ascending pass and re-run the gates; decide whether 10 MB is a supported size, since edits in the middle of a very large styled file still shift the tail.

From the performance review, docs/review-2026-11-21.md (#96).

Platforms: macOS, iOS.

closed by cmc in commit 13a0d02bad: Apply indents and roles in one ascending pass

2026-11-22 13:14 UTC