perf(core): defer tracer imports in runnables/base.py to call time#36920
Open
Sydney Runkle (sydney-runkle) wants to merge 9 commits intomasterfrom
Open
perf(core): defer tracer imports in runnables/base.py to call time#36920Sydney Runkle (sydney-runkle) wants to merge 9 commits intomasterfrom
Sydney Runkle (sydney-runkle) wants to merge 9 commits intomasterfrom
Conversation
…rios Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Move middleware construction inside benchmarked lambdas for fresh instances - Rework memory test to observation-only with print output (no hard assertion) - Add deeply-nested Pydantic schema tool (RouteSchema) to LARGE_TOOLS (15 tools) - Update docstrings to document '10 accesses per iteration' in schema benchmarks - Fix bare `_ =` pattern in schema benchmarks (bare expressions) - Mark memory test with @pytest.mark.benchmark to exclude from normal runs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tion Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
event_stream, log_stream, and root_listeners are only needed by astream_log and astream_events. Moving these imports inside those methods eliminates ~90ms from 'from langchain_core.language_models import BaseChatModel' by breaking the eager load chain into langsmith.schemas.
Merging this PR will improve performance by 52.38%
Performance Changes
Comparing Footnotes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
runnables/base.py(event_stream,log_stream,root_listeners,_streaming) that were pulled in on everyfrom langchain_core.language_models import BaseChatModelTYPE_CHECKINGand adds deferred imports at the call sites (astream_log,astream_events,with_listeners,with_alisteners)_StreamingCallbackHandlerat top level since it's a lightweight module needed for isinstance checksMotivation
The tracer import chain was the dominant cost in
from langchain_core.language_models import BaseChatModel:This eliminates ~76ms from the import chain, bringing
BaseChatModelimport from ~291ms down to ~160ms.Test plan
cd libs/core && uv run --group test pytest tests/unit_tests/runnables/ -x -q🤖 Generated with Claude Code