Edits in a file with non-ASCII text cost 3.3 ms per MB in the document model #199

open cmc opened this on 2026-11-22 07:11 UTC · feature · milestone Backlog

Discussion

cmc 2026-11-22 07:11 UTC

Severity: Medium.

DocumentState.applyGroup copies the text per edit and converts offsets with String.Index(utf16Offset:) (Sources/OrgDocument/DocumentState.swift:85-105, :178-182), which is linear for non-ASCII strings. One character: 0.2 ms at 1 MB and 1.6 ms at 10 MB for ASCII; 3.3 ms and 33.5 ms once the text has umlauts. Keep the text in a form with constant-time UTF-16 offsets or carry UTF-8 offsets in TextEdit.

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

Platforms: macOS, iOS.