Skip to content

perf(editor): eliminate quadratic line counting and substring allocations in SqlStatementSplitter (#1350) - #1453

Merged
ZhuchkaTriplesix merged 1 commit into
devfrom
issue/1350-sql-splitter-perf
Oct 11, 2026
Merged

ZhuchkaTriplesix merged 1 commit into
devfrom
issue/1350-sql-splitter-perf

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Closes #1350

Problem

  1. When parsing large SQL files, line counting in SqlStatementSplitter previously incurred quadratic scans O(N*M) and sql.substring(i) string allocations with dynamic RegExp creation on every dollar sign.
  2. Synchronous character-by-character scanning with sql[i] allocated individual character string objects across millions of characters.
  3. Splitting multi-megabyte scripts ran synchronously on the UI thread, risking dropped frames on query execution.

Solution

  • Kept the linear newline scan and static dollar tag regex.
  • Switched the scanner from sql[i] substring indexing to sql.codeUnitAt(i), eliminating all intermediate character allocations.
  • Added SqlStatementSplitter.spansAsync which offloads statement splitting to a background isolate via compute for scripts exceeding 64 KB (defaultIsolateThreshold).
  • Switched GenericSqlWorkspace._runSpans to async, leveraging spansAsync to protect UI responsiveness during script execution.
  • Added unit tests covering spansAsync (both sync below threshold and background isolate above threshold).

@github-actions github-actions Bot added the editor Code/SQL editor label Oct 11, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit 77a8d60 into dev Oct 11, 2026
13 checks passed
@github-actions github-actions Bot added performance Theme parser epic label: performance core Core library logic and services backend Backend database driver execution and queries P2 Medium priority / Parity & Refactoring labels Oct 11, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix deleted the issue/1350-sql-splitter-perf branch October 11, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend database driver execution and queries core Core library logic and services editor Code/SQL editor P2 Medium priority / Parity & Refactoring performance Theme parser epic label: performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant