Skip to content

Commit fbd9391

Browse files
committed
Python: CG trace: More caching
Improves runtime of tracing youtube-dl from 296.19 seconds to 224.50 seconds. Better, but still not that amazing :|
1 parent ce42221 commit fbd9391

File tree

1 file changed

+13
-1
lines changed
  • python/tools/recorded-call-graph-metrics/src/cg_trace

1 file changed

+13
-1
lines changed

python/tools/recorded-call-graph-metrics/src/cg_trace/tracer.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def canonic_filename(filename):
3636
return canonic
3737

3838

39+
_call_cache = dict()
40+
41+
3942
@dataclasses.dataclass(frozen=True, eq=True, order=True)
4043
class Call:
4144
"""A call
@@ -55,17 +58,26 @@ def __str__(self):
5558

5659
@classmethod
5760
def from_frame(cls, frame: FrameType):
61+
global _call_cache
62+
key = cls.hash_key(frame)
63+
if key in _call_cache:
64+
return _call_cache[key]
65+
5866
code = frame.f_code
5967

6068
bytecode_expr = expr_from_frame(frame)
6169

62-
return cls(
70+
call = cls(
6371
filename=canonic_filename(code.co_filename),
6472
linenum=frame.f_lineno,
6573
inst_index=frame.f_lasti,
6674
bytecode_expr=bytecode_expr,
6775
)
6876

77+
_call_cache[key] = call
78+
79+
return call
80+
6981
@staticmethod
7082
def hash_key(frame: FrameType) -> Tuple[str, int, int]:
7183
code = frame.f_code

0 commit comments

Comments
 (0)