Skip to content

perf(editor): linear line counting and no per-dollar allocations in SqlStatementSplitter - #1399

Merged
ZhuchkaTriplesix merged 1 commit into
devfrom
issue/1350-statement-splitter-linear
Oct 10, 2026
Merged

ZhuchkaTriplesix merged 1 commit into
devfrom
issue/1350-statement-splitter-linear

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Part of #1350

Problem

SqlStatementSplitter.spans recounted newlines from offset 0 for every statement (O(N*M)) and, on every $, copied the rest of the script with sql.substring(i) and compiled a new RegExp.

Change

  • Line numbers: statement starts only move forward, so the splitter keeps a running (offset, line) pair and counts newlines from the previous start. One pass in total; SqlStatementSpan.line is unchanged.
  • Dollar quotes: one static final RegExp, matched with matchAsPrefix(sql, i) (no ^, no substring).

Tests

Added to sql_statement_splitter_test.dart: exact line numbers over 5000 statements, newline counting with blank lines, a dollar quote far into the script, and $1 / $2 parameters not taken for quotes. Existing tests cover the rest.

Not in this PR

Point 3 of the issue (moving the split to an isolate above 64 KB) changes the call sites in GenericSqlWorkspace and is left for a separate PR; with the two fixes above the split is a single linear pass.

Not run locally; CI is the check.

…Splitter

Statement lines are counted incrementally from the previous statement
start instead of rescanning from the top of the script, and dollar quote
tags are matched with one static RegExp at the current offset instead of
copying the rest of the script into a substring on every dollar sign.
Part of #1350.
@github-actions github-actions Bot added editor Code/SQL editor 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 10, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit 333c5cf into dev Oct 10, 2026
15 checks passed
@ZhuchkaTriplesix
ZhuchkaTriplesix deleted the issue/1350-statement-splitter-linear branch October 11, 2026 15:03
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