perf(scip-syntax): uses the same parse tree for globals and locals#63564
Conversation
c90a6dc to
4d80665
Compare
There was a problem hiding this comment.
My typical rule of thumb is that if both branches of a pattern-match are being modified through some methods, it's clearer to replace that with an explicit pattern match. So something like:
let parser = match parser.entry(parser_id) {
Occupied(p) => p.reset(); ...
Vacant(v) => v.insert(parser_id.get_parser())
}
Otherwise, a method name like and_modify doesn't make it super clear what is happening, and a comment shouldn't be necessary for what is otherwise boring code.
There was a problem hiding this comment.
Happy to make the change, though the comment wasn't really about and_modify and more about the tree-sitter API requiring the use of .reset() when parsing a new document.
There was a problem hiding this comment.
In that case, a clearer comment would be something like Tree-sitter parsing is stateful, so reset the parser state explicitly.
There was a problem hiding this comment.
Actually I take that back. This is one of the cases where the entry API seems to be the easiest way to make the lifetimes work out. (I can't get a mutable reference from Occupied which I need to call .reset() on it)
I've removed the comment
There was a problem hiding this comment.
There was a problem hiding this comment.
Damnit, the UI didn't reload so I missed your comment.
There was a problem hiding this comment.
This doesn't work? https://doc.rust-lang.org/std/collections/hash_map/struct.OccupiedEntry.html#method.get_mut
It does give you a mutable reference, but you can't return it from the match after resetting, as it's bound to the lifetime of the pattern matched entry value.
There was a problem hiding this comment.
There was a problem hiding this comment.
Neat, that one worked.
4d80665 to
0a6222c
Compare
0a6222c to
5e0d179
Compare
Closes https://linear.app/sourcegraph/issue/GRAPH-718/dont-parse-every-file-twice-in-scip-syntax
While working on parallel scip-syntax I noticed we're re-parsing every file for both globals and locals generation. This PR makes it so we use the same parse tree for both. I've also made it so we don't re-initialize the language parsers for every file. The thread-local-storage aspect of this matters after merging #63536
Test plan