Skip to content

Commit 0c505ca

Browse files
Merge pull request #376 from codeflash-ai/pickle-patched-tracer
Pickle patched tracer
2 parents 21e8fe8 + c7a5985 commit 0c505ca

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

codeflash/tracer.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from pathlib import Path
3030
from typing import TYPE_CHECKING, Any, Callable, ClassVar
3131

32-
import dill
3332
import isort
3433
from rich.align import Align
3534
from rich.panel import Panel
@@ -41,6 +40,7 @@
4140
from codeflash.code_utils.code_utils import module_name_from_file_path
4241
from codeflash.code_utils.config_parser import parse_config_file
4342
from codeflash.discovery.functions_to_optimize import filter_files_optimized
43+
from codeflash.picklepatch.pickle_patcher import PicklePatcher
4444
from codeflash.tracing.replay_test import create_trace_replay_test
4545
from codeflash.tracing.tracing_utils import FunctionModules
4646
from codeflash.verification.verification_utils import get_test_file_path
@@ -399,22 +399,12 @@ def tracer_logic(self, frame: FrameType, event: str) -> None: # noqa: PLR0911
399399
arguments_copy = dict(arguments.items()) # Use the local 'arguments' from frame.f_locals
400400
if class_name and code.co_name == "__init__" and "self" in arguments_copy:
401401
del arguments_copy["self"]
402-
local_vars = pickle.dumps(arguments_copy, protocol=pickle.HIGHEST_PROTOCOL)
402+
local_vars = PicklePatcher.dumps(arguments_copy, protocol=pickle.HIGHEST_PROTOCOL)
403403
sys.setrecursionlimit(original_recursion_limit)
404404
except Exception:
405-
# we retry with dill if pickle fails. It's slower but more comprehensive
406-
try:
407-
sys.setrecursionlimit(10000) # Ensure limit is high for dill too
408-
# arguments_copy should be used here as well if defined above
409-
local_vars = dill.dumps(
410-
arguments_copy if "arguments_copy" in locals() else dict(arguments.items()),
411-
protocol=dill.HIGHEST_PROTOCOL,
412-
)
413-
sys.setrecursionlimit(original_recursion_limit)
414-
415-
except Exception:
416-
self.function_count[function_qualified_name] -= 1
417-
return
405+
self.function_count[function_qualified_name] -= 1
406+
sys.setrecursionlimit(original_recursion_limit)
407+
return
418408

419409
cur.execute(
420410
"INSERT INTO function_calls VALUES(?, ?, ?, ?, ?, ?, ?, ?)",

0 commit comments

Comments
 (0)