Skip to content

perf(sql): offset scanner for leading comments in sql_limit (#1515) - #1612

Merged
ZhuchkaTriplesix merged 1 commit into
devfrom
issue/1515-strip-leading-comments
Oct 15, 2026
Merged

ZhuchkaTriplesix merged 1 commit into
devfrom
issue/1515-strip-leading-comments

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Summary

stripLeadingWhitespaceAndLineComments did s.substring(nl + 1).trimLeft() / s.substring(blockEnd).trimLeft() for every leading comment, so a 10 MB dump with 50 header lines copied the remaining script 50 times before the query ran.

_skipLeadingCommentsOffset walks an index through whitespace (the exact set trimLeft removes), -- lines (to \n, as before) and nested /* */ blocks (reusing _blockCommentEnd from the same offset), and the function slices once. A script that is all comment / whitespace still gives ''.

Callers (injectSqlLimit, postgres_sql.dart, postgres_table_utils.dart) are unchanged.

Tests (not run locally; CI will)

test/core/database/sql_limit_strip_test.dart keeps the old implementation as the reference and compares about 25 listed scripts (CRLF, nested and unterminated blocks, only-comment scripts, -- without a newline,   / BOM / \u0085 / ᠎), 4000 seeded random scripts, and a 500-line header in front of a large body. The existing sql_limit_test.dart is untouched.

Closes #1515

…ndLineComments

Each leading comment copied the rest of the script (substring + trimLeft), so
a dump with a long header of comment lines in front of a large script was
quadratic in memory.

An index walks whitespace, -- lines and nested /* */ blocks and the string is
sliced once. The whitespace set is the one trimLeft uses. A test compares the
result with the previous implementation on listed and random scripts.

Closes #1515
@github-actions github-actions Bot added editor Code/SQL editor performance Theme parser epic label: performance core Core library logic and services P2 Medium priority / Parity & Refactoring labels Oct 15, 2026
@github-actions github-actions Bot added this to the 0.5.0 milestone Oct 15, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit 238174b into dev Oct 15, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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