Conversation
Replace per-call Path.is_relative_to() and Path.exists() (stat syscall) with a single cached lookup per unique co_filename. Use os.path.realpath and str.startswith instead of pathlib to avoid object allocation on the hot path. Profile showed these pathlib ops at ~15% self-time.
…uction Keep file_name as a plain str throughout the per-call path. Path is only constructed once per unique function in the first-time-seen branch where filter_files_optimized and FunctionModules need it.
|
this was causing 10-15% overhead |
PR Review SummaryPrek ChecksAll checks passed (ruff check, ruff format) — no issues found. Mypy48 pre-existing mypy errors in Code ReviewThis PR makes solid performance optimizations to the tracer hot path:
Minor issue found:
No critical bugs, security issues, or breaking API changes detected. Test Coverage
Last updated: 2026-02-27T14:50 UTC |
| # All paths are relative to this pyproject.toml's directory. | ||
| module-root = "codeflash" | ||
| tests-root = "codeflash" | ||
| tests-root = "tests" |
There was a problem hiding this comment.
The tests-root change from "codeflash" to "tests" breaks tests/test_worktree.py::test_mirror_paths_for_worktree_mode which hardcodes the old value:
# tests_root is configured as "codeflash" in pyproject.toml
assert optimizer.args.tests_root == worktree_dir / "codeflash"The test at lines 63-67 needs to be updated to expect worktree_dir / "tests" instead of worktree_dir / "codeflash".
| @@ -61,9 +61,9 @@ def test_mirror_paths_for_worktree_mode(monkeypatch: pytest.MonkeyPatch): | |||
| assert optimizer.args.test_project_root == worktree_dir | |||
| assert optimizer.args.module_root == worktree_dir / "codeflash" | |||
| # tests_root is configured as "codeflash" in pyproject.toml | |||
There was a problem hiding this comment.
Stale comment: says tests_root is configured as "codeflash" in pyproject.toml but it's now "tests".
| # tests_root is configured as "codeflash" in pyproject.toml | |
| # tests_root is configured as "tests" in pyproject.toml |
Summary
os.path.realpathandos.path.existscalls on repeated function entriesPath.is_relative_toandPath.resolvewithos.path.realpath+str.startswithin the hot path for lower overheadPathconstruction to first-seen functions only, keeping the per-call path as string-basedtests-roottotestsin pyproject.tomlTest plan
profile_callback