mirror of
https://github.com/safishamsi/graphify.git
synced 2026-09-21 13:05:41 +00:00
Merge pull request #1294 from sirphilliptubell/perf/fix4
perf: convert _walk_js_tree from recursive generator to iterative
This commit is contained in:
+8
-3
@@ -7421,9 +7421,14 @@ def _parse_js_tree(path: Path):
|
||||
|
||||
|
||||
def _walk_js_tree(node):
|
||||
yield node
|
||||
for child in node.children:
|
||||
yield from _walk_js_tree(child)
|
||||
# Iterative DFS avoids Python's O(depth) generator-chain overhead.
|
||||
# Recursive yield-from creates one generator frame per level — at 26+
|
||||
# levels deep each leaf's value had to propagate through 26 frames.
|
||||
stack = [node]
|
||||
while stack:
|
||||
n = stack.pop()
|
||||
yield n
|
||||
stack.extend(reversed(n.children))
|
||||
|
||||
|
||||
def _js_module_specifier(node, source: bytes) -> str | None:
|
||||
|
||||
Reference in New Issue
Block a user