Skip to content

Commit d141a48

Browse files
perf: improve performance of code-to-function lookups [backport 2.21] (#13400)
Backport 205fd1e from #13393 to 2.21. We increase the LRU cache size of the function-for-code lookup to avoid potentially excessive churn. The default size of 128 might be too small since it is a cache on a utility function that is shared by many other components. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: Gabriele N. Tornetta <[email protected]>
1 parent 91b8f48 commit d141a48

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

ddtrace/internal/utils/inspection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def collect_code_objects(code: CodeType) -> Iterator[CodeType]:
126126
q.append(new_code)
127127

128128

129-
@lru_cache()
129+
@lru_cache(maxsize=(1 << 14)) # 16k entries
130130
def functions_for_code(code: CodeType) -> List[FunctionType]:
131131
import gc
132132

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
code origin for spans: fixes a performance issue with exit spans.

0 commit comments

Comments
 (0)