Skip to content

Commit b470219

Browse files
authored
Merge pull request #1614 from codeflash-ai/codeflash/optimize-pr1561-2026-02-20T15.27.15
⚡️ Speed up method `TreeSitterAnalyzer.is_function_exported` by 866% in PR #1561 (`add/support_react`)
2 parents 9fd1565 + af52024 commit b470219

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

codeflash/languages/javascript/treesitter_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ def __init__(self, language: TreeSitterLanguage | str) -> None:
152152

153153
# Cache for function type sets keyed by (include_methods, include_arrow_functions)
154154
self._function_types_cache: dict[tuple[bool, bool], set[str]] = {}
155+
# Cache for exports to avoid repeated parsing
156+
self._exports_cache: dict[str, list[ExportInfo]] = {}
155157

156158
@property
157159
def parser(self) -> Parser:
@@ -691,12 +693,16 @@ def find_exports(self, source: str) -> list[ExportInfo]:
691693
List of ExportInfo objects describing exports.
692694
693695
"""
696+
if source in self._exports_cache:
697+
return self._exports_cache[source]
698+
694699
source_bytes = source.encode("utf8")
695700
tree = self.parse(source_bytes)
696701
exports: list[ExportInfo] = []
697702

698703
self._walk_tree_for_exports(tree.root_node, source_bytes, exports)
699704

705+
self._exports_cache[source] = exports
700706
return exports
701707

702708
def _walk_tree_for_exports(self, node: Node, source_bytes: bytes, exports: list[ExportInfo]) -> None:

0 commit comments

Comments
 (0)