diff --git a/libs/langgraph/profile.svg b/libs/langgraph/profile.svg deleted file mode 100644 index 5832e76ea..000000000 --- a/libs/langgraph/profile.svg +++ /dev/null @@ -1,415 +0,0 @@ -py-spy record -o profile.svg -- python ../../perf_test.py Reset ZoomSearch submit (concurrent/futures/thread.py:172) (9 samples, 0.14%)submit (concurrent/futures/thread.py:173) (11 samples, 0.17%)_aroute (graph/graph.py:101) (27 samples, 0.42%)to_thread (asyncio/threads.py:25) (27 samples, 0.42%)ainvoke (utils/runnable.py:145) (13 samples, 0.20%)get_async_callback_manager_for_config (langchain_core/runnables/config.py:503) (13 samples, 0.20%)configure (langchain_core/callbacks/manager.py:1996) (13 samples, 0.20%)_configure (langchain_core/callbacks/manager.py:2191) (12 samples, 0.19%)_tracing_v2_is_enabled (langchain_core/tracers/context.py:149) (12 samples, 0.19%)tracing_is_enabled (langsmith/utils.py:105) (12 samples, 0.19%)get_env_var (langsmith/utils.py:376) (10 samples, 0.16%)get (<frozen _collections_abc>:774) (10 samples, 0.16%)__getitem__ (<frozen os>:679) (10 samples, 0.16%)_aroute (graph/graph.py:108) (26 samples, 0.41%)astream (pregel/__init__.py:1397) (9 samples, 0.14%)__aenter__ (pregel/loop.py:698) (9 samples, 0.14%)enter_async_context (contextlib.py:650) (9 samples, 0.14%)__aenter__ (contextlib.py:210) (9 samples, 0.14%)astream (pregel/__init__.py:1422) (10 samples, 0.16%)to_thread (asyncio/threads.py:25) (8 samples, 0.12%)_output_writes (pregel/loop.py:513) (9 samples, 0.14%)_emit (pregel/loop.py:506) (8 samples, 0.12%)<genexpr> (pregel/loop.py:513) (8 samples, 0.12%)atick (pregel/runner.py:131) (16 samples, 0.25%)put_writes (pregel/loop.py:227) (16 samples, 0.25%)_output_writes (pregel/loop.py:518) (7 samples, 0.11%)_emit (pregel/loop.py:506) (7 samples, 0.11%)<genexpr> (pregel/loop.py:518) (7 samples, 0.11%)astream (pregel/__init__.py:1429) (21 samples, 0.33%)ainvoke (pregel/__init__.py:1539) (52 samples, 0.81%)ensure_config (langchain_core/runnables/config.py:174) (14 samples, 0.22%)<dictcomp> (langchain_core/runnables/config.py:175) (14 samples, 0.22%)copy (langchain_core/callbacks/base.py:913) (13 samples, 0.20%)__init__ (langchain_core/callbacks/base.py:907) (7 samples, 0.11%)ainvoke (utils/runnable.py:142) (34 samples, 0.53%)ainvoke (utils/runnable.py:145) (12 samples, 0.19%)get_async_callback_manager_for_config (langchain_core/runnables/config.py:503) (12 samples, 0.19%)configure (langchain_core/callbacks/manager.py:1996) (12 samples, 0.19%)ainvoke (utils/runnable.py:146) (8 samples, 0.12%)ainvoke (utils/runnable.py:154) (7 samples, 0.11%)shield (asyncio/tasks.py:884) (13 samples, 0.20%)_ensure_future (asyncio/tasks.py:680) (13 samples, 0.20%)ainvoke (utils/runnable.py:164) (14 samples, 0.22%)wrapped (langchain_core/callbacks/manager.py:237) (14 samples, 0.22%)ensure_config (langchain_core/runnables/config.py:176) (10 samples, 0.16%)ainvoke (utils/runnable.py:359) (16 samples, 0.25%)tracing_is_enabled (langsmith/utils.py:105) (8 samples, 0.12%)get_env_var (langsmith/utils.py:376) (8 samples, 0.12%)get (<frozen _collections_abc>:774) (8 samples, 0.12%)ainvoke (utils/runnable.py:360) (31 samples, 0.48%)get_async_callback_manager_for_config (langchain_core/runnables/config.py:503) (28 samples, 0.44%)configure (langchain_core/callbacks/manager.py:1996) (28 samples, 0.44%)_configure (langchain_core/callbacks/manager.py:2191) (10 samples, 0.16%)_tracing_v2_is_enabled (langchain_core/tracers/context.py:149) (10 samples, 0.16%)shield (asyncio/tasks.py:884) (10 samples, 0.16%)_ensure_future (asyncio/tasks.py:680) (9 samples, 0.14%)arun_with_retry (pregel/retry.py:79) (81 samples, 1.27%)ainvoke (utils/runnable.py:391) (14 samples, 0.22%)wrapped (langchain_core/callbacks/manager.py:237) (14 samples, 0.22%)<module> (perf_test.py:81) (379 samples, 5.92%)<module>..run (asyncio/runners.py:190) (379 samples, 5.92%)run (asy..run (asyncio/runners.py:118) (379 samples, 5.92%)run (asy.._worker (concurrent/futures/thread.py:81) (5,805 samples, 90.66%)_worker (concurrent/futures/thread.py:81)local_read (pregel/algo.py:109) (9 samples, 0.14%)ChannelsManager (pregel/manager.py:44) (10 samples, 0.16%)__enter__ (contextlib.py:137) (15 samples, 0.23%)local_read (pregel/algo.py:110) (24 samples, 0.37%)__exit__ (contextlib.py:144) (9 samples, 0.14%)ChannelsManager (pregel/manager.py:42) (9 samples, 0.14%)__exit__ (contextlib.py:586) (7 samples, 0.11%)do_read (pregel/read.py:102) (42 samples, 0.66%)local_read (pregel/algo.py:114) (9 samples, 0.14%)do_read (pregel/read.py:86) (8 samples, 0.12%)tick (pregel/loop.py:257) (21 samples, 0.33%)apply_writes (pregel/algo.py:218) (11 samples, 0.17%)update (channels/last_value.py:45) (9 samples, 0.14%)tick (pregel/loop.py:267) (10 samples, 0.16%)_emit (pregel/loop.py:506) (10 samples, 0.16%)<genexpr> (pregel/loop.py:267) (10 samples, 0.16%)map_output_values (pregel/io.py:86) (10 samples, 0.16%)<setcomp> (pregel/io.py:86) (10 samples, 0.16%)tick (pregel/loop.py:285) (8 samples, 0.12%)<genexpr> (pregel/algo.py:383) (16 samples, 0.25%)read_channel (pregel/io.py:19) (16 samples, 0.25%)get (channels/ephemeral_value.py:65) (7 samples, 0.11%)prepare_next_tasks (pregel/algo.py:379) (21 samples, 0.33%)prepare_next_tasks (pregel/algo.py:406) (31 samples, 0.48%)tick (pregel/loop.py:300) (85 samples, 1.33%)prepare_next_tasks (pregel/algo.py:425) (15 samples, 0.23%)run (concurrent/futures/thread.py:58) (206 samples, 3.22%)run..tick (pregel/loop.py:364) (18 samples, 0.28%)_emit (pregel/loop.py:506) (18 samples, 0.28%)<genexpr> (pregel/loop.py:364) (18 samples, 0.28%)map_debug_tasks (pregel/debug.py:94) (13 samples, 0.20%)_worker (concurrent/futures/thread.py:83) (209 samples, 3.26%)_wo..all (6,403 samples, 100%)_bootstrap (threading.py:1002) (6,017 samples, 93.97%)_bootstrap (threading.py:1002)_bootstrap_inner (threading.py:1045) (6,017 samples, 93.97%)_bootstrap_inner (threading.py:1045)run (threading.py:982) (6,017 samples, 93.97%)run (threading.py:982) \ No newline at end of file diff --git a/perf_test_sync.py b/perf_test_sync.py deleted file mode 100644 index ac3e1a07f..000000000 --- a/perf_test_sync.py +++ /dev/null @@ -1,80 +0,0 @@ -import operator -import random -from time import perf_counter_ns -from typing import Annotated, TypedDict - -from langgraph.checkpoint.sqlite import SqliteSaver -from langgraph.constants import END, START, Send -from langgraph.graph.state import StateGraph - - -class OverallState(TypedDict): - subjects: list[str] - jokes: Annotated[list[str], operator.add] - - -def continue_to_jokes(state: OverallState): - return [Send("generate_joke", {"subject": s}) for s in state["subjects"]] - - -class JokeInput(TypedDict): - subject: str - - -class JokeOutput(TypedDict): - jokes: list[str] - - -def bump(state: JokeOutput): - return {"jokes": [state["jokes"][0] + " a"]} - - -def generate(state: JokeInput): - return {"jokes": [f"Joke about {state['subject']}"]} - - -def edit(state: JokeInput): - subject = state["subject"] - return {"subject": f"{subject} - hohoho"} - - -def bump_loop(state: JokeOutput): - return END if state["jokes"][0].endswith(" a" * 10) else "bump" - - -# subgraph -subgraph = StateGraph(input=JokeInput, output=JokeOutput) -subgraph.add_node("edit", edit) -subgraph.add_node("generate", generate) -subgraph.add_node("bump", bump) -subgraph.set_entry_point("edit") -subgraph.add_edge("edit", "generate") -subgraph.add_edge("generate", "bump") -subgraph.add_conditional_edges("bump", bump_loop) -subgraph.set_finish_point("generate") -subgraphc = subgraph.compile() - -# parent graph -builder = StateGraph(OverallState) -builder.add_node("generate_joke", subgraphc) -builder.add_conditional_edges(START, continue_to_jokes) -builder.add_edge("generate_joke", END) - - -def main(): - with SqliteSaver.from_conn_string(":memory:") as checkpointer: - graph = builder.compile(checkpointer=checkpointer) - config = {"configurable": {"thread_id": "1"}} - input = { - "subjects": [ - random.choice("abcdefghijklmnopqrstuvwxyz") for _ in range(100) - ] - } - - # invoke and pause at nested interrupt - s = perf_counter_ns() - assert len([c for c in graph.stream(input, config=config)]) == 100 - print("Time taken:", (perf_counter_ns() - s) / 1e9) - - -main()