You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(editor): eliminate quadratic line counting and substring allocations in SqlStatementSplitter #1350
Quadratic Line Counting ((N \cdot M)$):
In close(int end) (lines 40–42):
out.add(SqlStatementSpan(start: s, end: e, line:_lineOf(sql, s)));
_lineOf(sql, s) (lines 147–153) iterates from 0 to offset counting newline characters (0x0A) on every statement. For a script with $ statements across $ lines, this performs (N \cdot M) \approx O(N^2)$ characters scans. In large SQL dumps or multi-statement migration scripts, this quadratic scanning takes seconds.
Per-Dollar Substring Allocations & Dynamic RegExp:
In lines 67–76:
if (c =='\$') {
final match =RegExp(r'^\\$').matchAsPrefix(sql.substring(i));
On every $ character encountered (including numbered parameters like $1, $2), sql.substring(i) copies the entire remainder of the script into a new string, and compiles a fresh RegExp instance. For a 5 MB file with dollar quotes or parameters, this creates massive transient allocations and GC pressure.
UI Thread Blocking: SqlStatementSplitter.spans is invoked synchronously on the UI thread in GenericSqlWorkspace._runSpans whenever the user executes a statement or script (Ctrl+Enter / F5).
Proposed Solution
Maintain a running currentLine counter during the main character iteration in SqlStatementSplitter.spans, turning line tracking into a strict (N)$ single pass.
Use a static compiled RegExp and pass the search offset start: i to matchAsPrefix(sql, i) instead of allocating sql.substring(i).
Offload statement splitting to an isolate via compute if script length exceeds a threshold (e.g. 64 KB).
Acceptance Criteria
Statement splitting runs in linear (N)$ time with no quadratic line counting.
No string allocations or dynamic regex creations occur on $ tokens.
SqlStatementSpan.line calculations remain 100% accurate across all test scripts.
Fixed in #1453 (and #1399) by using single-pass linear line counting, static dollar tag RegExp, zero-string-allocation scanner with codeUnitAt, and background isolate offloading via compute for large scripts (>64KB) in SqlStatementSplitter.spansAsync.
Activity
Merge pull request #1453 from QueryaHub/issue/1350-sql-splitter-perf
ZhuchkaTriplesix commentedon Oct 11, 2026
Fixed in #1453 (and #1399) by using single-pass linear line counting, static dollar tag RegExp, zero-string-allocation scanner with codeUnitAt, and background isolate offloading via compute for large scripts (>64KB) in SqlStatementSplitter.spansAsync.