Skip to content

perf: use deque for BFS queue in graph traversal#1494

Merged
skrawcz merged 2 commits intoapache:mainfrom
giulio-leone:fix/graph-bfs-deque
Mar 1, 2026
Merged

perf: use deque for BFS queue in graph traversal#1494
skrawcz merged 2 commits intoapache:mainfrom
giulio-leone:fix/graph-bfs-deque

Conversation

@giulio-leone
Copy link
Contributor

Problem

compute_nodes_from_sources() in hamilton/execution/graph_functions.py uses .pop(0) for BFS queue traversal, which is O(n) per removal.

Solution

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

compute_nodes_from_sources() drains a BFS queue via .pop(0) which is
O(n) per removal.  Switch to collections.deque with .popleft() for
O(1) front removal.
@giulio-leone
Copy link
Contributor Author

Friendly ping — CI is green and this is ready for review. Happy to address any feedback. Thanks!

@skrawcz
Copy link
Contributor

skrawcz commented Feb 28, 2026

Thanks @giulio-leone, there seems to be a linting issue please run the pre-commit hooks and try again.

@skrawcz skrawcz merged commit 072c40c into apache:main Mar 1, 2026
5 checks passed
@skrawcz
Copy link
Contributor

skrawcz commented Mar 1, 2026

thanks!

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.

2 participants