Repository navigation
Conversation
…r the whole file get_statement_for_completions counted every statement of the document, which maps each of them and looks up its parse result, and then filtered all statements for the ones around the cursor. It only needs to know whether there are none, one or more statements, and the filter only accepts statements that contain the cursor or end up to two characters before it, so it now looks at those only.
This branch has not been deployed
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.
Stacked on #982. It only touches the workspace, and it needs
Document::splitfrom #964 and the stack-safeParseIteratorfrom #956. It doesn't depend on #983, but the numbers below were measured with #983 applied too.Every completion request had a cost linear in the file before it got to the completion itself.
get_statement_for_completionscalledDocument::count(), which runs every statement through the statement iterator: a parse-cache lookup for each statement, a check for a SQL function body, and a copy of its text. Then it ranGetCompletionsFilterover all statements to find the ones around the cursor. At 20,000 statements that was about 50 ms per keystroke.What changed
doc.iter(DefaultMapper).take(2).count().Document::counthad no other user and is removed.Document::iter_for_completions(mapper, position)runs the same filter, but only over the top-level statements that it can accept. Those contain the cursor, or end at most two characters before it. Two binary searches over the split's ranges find them. The bodies of SQL functions are inside their top-level statement, so they are still included.Test
finds_the_statement_like_a_filter_over_all_statementsbuilds a document with every case the filter cares about:;;At every position, it compares the result with the lookup from before, which filters all statements. The existing completion tests pass.
Numbers
Release build, 20 keystrokes, the scenarios from #982, with #983 applied. #982 + #983 → this PR:
What remains near the end of the file is mostly
pgls_completions::completeitself, which goes over the 5,000 tables, 20,000 columns and 5,000 functions that the file adds to the snapshot. A database with that many objects costs the same.