Skip to content

perf: parse SQL off the main thread and shrink result rows - #4340

Merged
datlechin merged 2 commits into
mainfrom
perf/editor-parse-and-row-storage
Nov 19, 2026
Merged

datlechin merged 2 commits into
mainfrom
perf/editor-parse-and-row-storage

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • P43: TextView.updateFrameIfNeeded keeps line layout when the frame width changes with wrapping off. Unwrapped lines are typeset at an unbounded width, so only wrapped lines lay out again.
  • P44: an async tree-sitter parse reads a UTF-16 snapshot of the document taken when the edit arrives, instead of taking the main thread for every 50 ms parse slice.
  • P44: every edit state has not taken stays on pendingEdits in arrival order, and a parse commits on the main thread only while no newer edit or set up has arrived.
  • P44: a cancelled parse no longer puts its edit back late, which could reorder a burst of edits or apply a stale edit to the tree a new set up built.
  • P45: Row holds its id and values only, 96 to 32 bytes. Missing fields, unloaded values and export snapshots move to SparseRowState in TableRows, keyed by row id.
  • P45: RowPositions replaces the [RowID: Int] index. Rows read in order resolve by position, and only added or reordered rows are hashed.
  • P45: the first write to the active result releases the ResultSet copy of the buffer it shares with the tab, so that write no longer copies every row. Switching results hands the buffer back as before.
  • Tests that read the moved row state through Row now read it through TableRows, same expectations: FieldAbsenceTrackingTests, RowOperationsFieldAbsenceTests, DocumentExportDataSourceTests, ResultComparisonGridModelTests, ResultSetComparisonTests, UnloadedValueReaderTests, MaskingExportTests.

Test plan

  • Fails on the old code, passes here: TreeSitterBackgroundParseTests (parse finishes while the main thread is blocked; an edit cancelled by a set up stays out of the new tree) and TextLayoutManagerLineWidthTests (growing the widest line keeps other lines), each run against the old source. TableRowsSparseStateTests (row stride 32) and ActiveResultBufferOwnerTests (first edit keeps the buffer) check what the probe below measured on the old shapes: a 96-byte row and a copied buffer.
  • New coverage for the moved state: positional lookups after appends, inserts, removals, reorders and repeated ids; sparse state through reorder, removal, writes and loads; flush on switch.
  • verify.sh test (Unit plan): 32,033 passed, 0 failed. verify.sh package TableProEditor: 879 passed.
  • Editor bench, 2,000,000 characters, wrap off, 8 s of typing sampled: main thread samples in the tree-sitter parse 847 of 3,763 before, 0 of 3,659 after; in layoutLines 1,284 before, 363 after. Keys typed in 12 s: 113 before, 288 after.
  • Snapshot cost at 2,000,000 characters: about 0.5 ms per keystroke (getCharacters).
  • Row probe, 1,000,000 rows: rows plus index 163 bytes per row before, 32 after, cell payload excluded. First edit with the buffer shared 88.9 ms, with one owner 0.003 ms.
  • Measured on a shared machine at load 40 to 100, so wall times are noisy; sample counts and bytes are not.

@datlechin
datlechin enabled auto-merge (squash) November 19, 2026 05:39
@datlechin
datlechin merged commit b3bde74 into main Nov 19, 2026
11 checks passed
@datlechin
datlechin deleted the perf/editor-parse-and-row-storage branch November 19, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant