Skip to content

perf(editor): scan a large script's run controls off the main thread - #4571

Merged
datlechin merged 4 commits into
mainfrom
perf/editor-statement-index
Nov 26, 2026
Merged

datlechin merged 4 commits into
mainfrom
perf/editor-statement-index

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • The run controls of a document past the 64,000-unit synchronous limit are scanned off the main actor. The refresh takes a snapshot of the text on the next turn of the main actor, so a call made inside an editing batch reads the edited text, scans it in a @concurrent function, and replaces the controls only if no edit, grammar change or statement model change landed meanwhile. The same path serves first open, a replaced document and a grammar change, which also scanned the whole document on the main thread.
  • Keyword auto-case no longer lexes from offset 0 to the caret on every keyword it would change. It reads from the start of the caret's statement, which SQLStatementCursorIndex already keeps: a statement never starts inside a literal or comment. The start is asked for only once the word is a keyword in the wrong case, so a plain word boundary costs nothing more than before.
  • Ships the part of perf(editor): keep statement boundaries in an index that edits update #4534 that stands alone. The incremental index that resyncs after an edit, checkpoints inside one long statement, and a gutter that asks only for the drawn range are left, as the issue comment says.

Measured:

What Before After
Main-thread work of a controls refresh at 2,000,000 units one full scan, 31 ms (the scanner's own figure) creating a task; the scan runs on the cooperative pool
Units scanned for the statement start after typing a keyword at the end of a 400,000-unit script 400,000 (lexed from 0 each time) at most 4,116 (one checkpoint span)

Test plan

  • StatementRunControllerTests: a large document's controls arrive from the background scan and equal a fresh scan, with nothing assigned on the call itself; a refresh asked for before an edit reads the edited text; the keyword-case statement start equals the scanner's and costs one checkpoint span, and another grammar gets 0.
  • KeywordUppercaseHelperTests: reading from a statement start gives the same answer as reading from the top.
  • Lint passes on every changed file. The local test runs were still queued behind the shared build lock when this opened, so CI's Unit plan and TableProCore package job are the run of record.

This PR and #4562 both touch StatementRunController.scheduleControlsRefresh; whichever merges second takes a one-line merge.

Closes #4534

The gutter's run controls rescanned the whole document on the main actor
after each typing pause, 31 ms at the size limit, and on first open, a
replaced document and a grammar change. Above the synchronous limit the scan
now runs in a @Concurrent function on a snapshot taken on the next turn of
the main actor, and its result is dropped if an edit, grammar or statement
model change landed meanwhile.

Keyword auto-case lexed from offset 0 to the caret to tell whether a word
sits in a literal or comment. It now reads from the start of the caret's
statement, which SQLStatementCursorIndex keeps and which never lies inside
one, and asks for it only once the word is a keyword in the wrong case.
@datlechin
datlechin enabled auto-merge (squash) November 26, 2026 01:50
…-index

# Conflicts:
#	apple/TablePro/Views/Editor/StatementRunController.swift
@datlechin
datlechin merged commit 917c297 into main Nov 26, 2026
8 of 10 checks passed
@datlechin
datlechin deleted the perf/editor-statement-index branch November 27, 2026 16:36
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.

perf(editor): keep statement boundaries in an index that edits update

1 participant