fix: resolve runtime decorator reconstruction overhead in trace_call (#594)#598
Open
suhaniiz wants to merge 1 commit into
Open
fix: resolve runtime decorator reconstruction overhead in trace_call (#594)#598suhaniiz wants to merge 1 commit into
suhaniiz wants to merge 1 commit into
Conversation
Contributor
Author
|
hey @param20h , this pr is under gssoc 2026, kindly review it and lemme know if any changes are to be made |
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.
🔗 Related Issue
Closes #594
📝 What does this PR do?
This PR eliminates a significant CPU performance bottleneck occurring during high-throughput execution loops (such as batch processing or streaming data chunks in the RAG pipeline).
Previously,
_build_traceable()was called insidetrace_callon every single invocation, dynamically reconstructing the underlying LangSmith SDK decorator. This caused massive dynamic allocation churn and high CPU overhead.Changes introduced:
_get_cached_decoratorusingfunctools.lru_cacheto store and reuse identical decorator definitions.metadatadictionary into an immutable, sortedtuplekey structure so it can safely be memoized by the cache._get_cached_traced_fnto cache the application of the decorator to a given target function, avoiding redundant runtime execution paths entirely.🗂️ Type of Change
🧪 How was this tested?
uvicorn app.main:app --reload)📸 Screenshots (if UI change)
N/A
The
lru_cachebounds have been explicitly limited (maxsize=1024) to ensure memory consumption stays tightly bounded, preventing potential memory leaks from long-running application runtimes or dynamic tracing setups.✅ Self-Review Checklist
dev, notmainmainbranch or any HuggingFace deployment config