-
Notifications
You must be signed in to change notification settings - Fork 21
⚡️ Speed up function _insert_declaration_after_dependencies by 1,230% in PR #1546 (follow-up-reference-graph)
#1549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,8 @@ | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| from tree_sitter import Node, Tree | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| _PARSER_CACHE: dict[TreeSitterLanguage, Parser] = {} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| logger = logging.getLogger(__name__) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -1770,6 +1772,18 @@ def _extract_type_definition( | |||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @property | ||||||||||||||||||||||
| def parser(self) -> Parser: | ||||||||||||||||||||||
| """Get or create the cached parser for this language.""" | ||||||||||||||||||||||
| if self._parser is None: | ||||||||||||||||||||||
| # Check if we have a cached parser for this language | ||||||||||||||||||||||
| if self.language not in _PARSER_CACHE: | ||||||||||||||||||||||
| _PARSER_CACHE[self.language] = Parser() | ||||||||||||||||||||||
| # Assuming parser setup happens elsewhere or in subclass | ||||||||||||||||||||||
| self._parser = _PARSER_CACHE[self.language] | ||||||||||||||||||||||
|
Comment on lines
1774
to
+1783
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical Bug: Duplicate This property redefines the existing The original creates This also causes
Suggested change
The duplicate should be removed entirely. If parser caching is desired, modify the existing |
||||||||||||||||||||||
| return self._parser | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def get_analyzer_for_file(file_path: Path) -> TreeSitterAnalyzer: | ||||||||||||||||||||||
| """Get the appropriate TreeSitterAnalyzer for a file based on its extension. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Cache stores uninitialized parsers
_PARSER_CACHEis populated withParser()(no language) at line 1780. These parsers have no grammar loaded and will fail when used to parse code.If parser caching is the goal, the cache should store properly initialized parsers:
However, since the duplicate
parserproperty that populates this cache should be removed (see other comment), this cache variable becomes unused and should also be removed.