Skip to content

Commit 29ccfdc

Browse files
authored
chore(di): cache function code pair resolution (#11757)
We make sure to cache the result of the function code pair resolution for subsequent calls. ## 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)
1 parent 7b77598 commit 29ccfdc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ddtrace/debugging/_function/discovery.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def resolve(self) -> FullyNamedFunction:
159159
msg = f"Multiple functions found for code object {code}"
160160
raise ValueError(msg)
161161

162-
f = cast(FullyNamedFunction, functions[0])
162+
self.function = _f = functions[0]
163+
f = cast(FullyNamedFunction, _f)
163164
f.__fullname__ = f"{f.__module__}.{f.__qualname__}"
164165

165166
return f
@@ -254,15 +255,17 @@ def __init__(self, module: ModuleType) -> None:
254255
if hasattr(module, "__dd_code__"):
255256
for code in module.__dd_code__:
256257
fcp = _FunctionCodePair(code=code)
258+
257259
if PYTHON_VERSION_INFO >= (3, 11):
258260
# From this version of Python we can derive the qualified
259261
# name of the function directly from the code object.
260262
fullname = f"{module.__name__}.{code.co_qualname}"
261263
self._fullname_index[fullname] = fcp
262264
else:
263265
self._name_index[code.co_name].append(fcp)
266+
264267
for lineno in linenos(code):
265-
self[lineno].append(_FunctionCodePair(code=code))
268+
self[lineno].append(fcp)
266269
else:
267270
# If the module was already loaded we don't have its code object
268271
seen_functions = set()

0 commit comments

Comments
 (0)