️ Speed up method Graph.find_runnable_predecessors_for_successor by 129% in PR #6309 (fix-order-loop) (#6310)

* feat: add is_loop property to Vertex class for detecting looping outputs

* feat: improve vertex runnability logic for graph traversal

- Update `is_vertex_runnable` to handle loop vertices more robustly
- Modify `are_all_predecessors_fulfilled` to better manage cycle dependencies
- Change adjacency maps to use sets for more efficient predecessor/successor tracking

* ️ Speed up method `Graph.find_runnable_predecessors_for_successor` by 129% in PR #6309 (`fix-order-loop`)
Here's the optimized version of the program.

### Changes and Optimizations.

* fix(serialization.py): update isinstance check for list and tuple to use union operator for better type checking

---------

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
This commit is contained in:
codeflash-ai[bot] 2025-02-13 12:38:01 +00:00 committed by GitHub
commit 1b6675ef68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 7 deletions

View file

@ -1979,21 +1979,21 @@ class Graph:
runnable_vertices = []
visited = set()
def find_runnable_predecessors(predecessor: Vertex) -> None:
predecessor_id = predecessor.id
def find_runnable_predecessors(predecessor_id: str) -> None:
if predecessor_id in visited:
return
visited.add(predecessor_id)
is_active = self.get_vertex(predecessor_id).is_active()
is_loop = self.get_vertex(predecessor_id).is_loop
predecessor_vertex = self.get_vertex(predecessor_id)
is_active = predecessor_vertex.is_active()
is_loop = predecessor_vertex.is_loop
if self.run_manager.is_vertex_runnable(predecessor_id, is_active=is_active, is_loop=is_loop):
runnable_vertices.append(predecessor_id)
else:
for pred_pred_id in self.run_manager.run_predecessors.get(predecessor_id, []):
find_runnable_predecessors(self.get_vertex(pred_pred_id))
find_runnable_predecessors(pred_pred_id)
for predecessor_id in self.run_manager.run_predecessors.get(vertex_id, []):
find_runnable_predecessors(self.get_vertex(predecessor_id))
find_runnable_predecessors(predecessor_id)
return runnable_vertices
def remove_from_predecessors(self, vertex_id: str) -> None:

View file

@ -111,7 +111,7 @@ def _truncate_value(value: Any, max_length: int | None, max_items: int | None) -
"""Truncate value based on its type and provided limits."""
if max_length is not None and isinstance(value, str) and len(value) > max_length:
return value[:max_length]
if max_items is not None and isinstance(value, (list, tuple)) and len(value) > max_items:
if max_items is not None and isinstance(value, list | tuple) and len(value) > max_items:
return value[:max_items]
return value