|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +from pathlib import Path |
3 | 4 | from typing import TYPE_CHECKING |
4 | 5 |
|
5 | 6 | from codeflash.cli_cmds.console import logger |
6 | 7 | from codeflash.code_utils.config_consts import DEFAULT_IMPORTANCE_THRESHOLD |
| 8 | +from codeflash.discovery.functions_to_optimize import FunctionToOptimize |
7 | 9 | from codeflash.tracing.profile_stats import ProfileStats |
8 | 10 |
|
9 | 11 | if TYPE_CHECKING: |
@@ -81,14 +83,13 @@ def load_function_stats(self) -> None: |
81 | 83 | self._function_stats = {} |
82 | 84 |
|
83 | 85 | def _get_function_stats(self, function_to_optimize: FunctionToOptimize) -> dict | None: |
84 | | - possible_keys = [ |
85 | | - f"{function_to_optimize.file_path}:{function_to_optimize.qualified_name}", |
86 | | - f"{function_to_optimize.file_path}:{function_to_optimize.function_name}", |
87 | | - ] |
88 | | - for key in possible_keys: |
89 | | - if key in self._function_stats: |
90 | | - return self._function_stats[key] |
91 | | - return None |
| 86 | + # First try qualified_name, then function_name, avoid allocating a list |
| 87 | + key1 = f"{function_to_optimize.file_path}:{function_to_optimize.qualified_name}" |
| 88 | + stats = self._function_stats.get(key1) |
| 89 | + if stats is not None: |
| 90 | + return stats |
| 91 | + key2 = f"{function_to_optimize.file_path}:{function_to_optimize.function_name}" |
| 92 | + return self._function_stats.get(key2, None) |
92 | 93 |
|
93 | 94 | def get_function_ttx_score(self, function_to_optimize: FunctionToOptimize) -> float: |
94 | 95 | stats = self._get_function_stats(function_to_optimize) |
|
0 commit comments