Skip to content

perf: use deque for BFS queue in get_function_dependency()#1952

Open
giulio-leone wants to merge 1 commit intoFoundationAgents:mainfrom
giulio-leone:fix/sanitize-bfs-deque-performance
Open

perf: use deque for BFS queue in get_function_dependency()#1952
giulio-leone wants to merge 1 commit intoFoundationAgents:mainfrom
giulio-leone:fix/sanitize-bfs-deque-performance

Conversation

@giulio-leone
Copy link

Problem

get_function_dependency() traverses the call graph via BFS using list.pop(0), which is O(n) per removal. For large call graphs this makes traversal O(n²).

Solution

Switch to collections.deque with .popleft() for O(1) front removal.

Changes

  • metagpt/utils/sanitize.py: Import deque, init queue as deque([entrypoint]), use .popleft()

Testing

  • Syntax verified via ast.parse()

get_function_dependency() traverses the call graph via BFS using
list.pop(0), which is O(n) per removal.  Switch to collections.deque
with popleft() for O(1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant