Repository navigation
perf(sql): offset scanner for leading comments in sql_limit (#1515) - #1612
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
stripLeadingWhitespaceAndLineCommentsdids.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._skipLeadingCommentsOffsetwalks an index through whitespace (the exact settrimLeftremoves),--lines (to\n, as before) and nested/* */blocks (reusing_blockCommentEndfrom 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.dartkeeps 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 existingsql_limit_test.dartis untouched.Closes #1515