diff --git a/libs/langgraph/Makefile b/libs/langgraph/Makefile index 85b8674de..bfad74585 100644 --- a/libs/langgraph/Makefile +++ b/libs/langgraph/Makefile @@ -1,4 +1,4 @@ -.PHONY: all format lint type test test_watch integration_tests spell_check spell_fix benchmark benchmark-profile benchmark-profile-spy profile start-dev-server integration_tests +.PHONY: all format lint type test test_watch integration_tests spell_check spell_fix benchmark profile start-dev-server integration_tests # Default target executed when no arguments are given to make. all: help @@ -24,14 +24,6 @@ benchmark-fast: rm -f $(OUTPUT) uv run python -m bench -o $(OUTPUT) --fast -benchmark-profile: - mkdir -p out - uv run python -m bench --profile - -benchmark-profile-spy: - mkdir -p out - sudo uv run py-spy record -g -o out/benchmark-flamegraph.svg -- python -m bench --fast - GRAPH ?= bench/fanout_to_subgraph.py profile: diff --git a/libs/langgraph/bench/__main__.py b/libs/langgraph/bench/__main__.py index 2e8bf8402..d824abe5f 100644 --- a/libs/langgraph/bench/__main__.py +++ b/libs/langgraph/bench/__main__.py @@ -1,9 +1,10 @@ import random -import sys from uuid import uuid4 from langchain_core.messages import HumanMessage from langgraph.checkpoint.memory import InMemorySaver +from pyperf._runner import Runner +from uvloop import new_event_loop from bench.fanout_to_subgraph import fanout_to_subgraph, fanout_to_subgraph_sync from bench.pydantic_state import pydantic_state @@ -463,54 +464,6 @@ benchmarks = ( ) -if "--profile" in sys.argv: - import asyncio - import cProfile - import pstats - from pathlib import Path - - out_dir = Path("out") - out_dir.mkdir(exist_ok=True) - - for name, agraph, graph, input_data in benchmarks: - # Profile async variant - prof = cProfile.Profile() - prof.enable() - asyncio.run(arun(agraph, input_data)) - prof.disable() - - prof_path = out_dir / f"{name}.prof" - prof.dump_stats(str(prof_path)) - - print(f"\n{'=' * 60}") - print(f"PROFILE: {name}") - print(f"{'=' * 60}") - stats = pstats.Stats(prof) - stats.sort_stats("cumulative") - stats.print_stats(20) - - # Profile sync variant - if graph is not None: - prof = cProfile.Profile() - prof.enable() - run(graph, input_data) - prof.disable() - - prof_path = out_dir / f"{name}_sync.prof" - prof.dump_stats(str(prof_path)) - - print(f"\n{'=' * 60}") - print(f"PROFILE: {name}_sync") - print(f"{'=' * 60}") - stats = pstats.Stats(prof) - stats.sort_stats("cumulative") - stats.print_stats(20) - - sys.exit(0) - -from pyperf._runner import Runner -from uvloop import new_event_loop - r = Runner() # Full graph run time