perf: remove redundant project_root_path.resolve() from hot path#1541
perf: remove redundant project_root_path.resolve() from hot path#1541
Conversation
StdlibIntegration monkeypatches subprocess.Popen, adding span/breadcrumb overhead to every subprocess call. Profiling showed ~342k samples (~8.9% of total runtime) in sentry_sdk.integrations.stdlib and sentry_sdk.utils. Disable subprocess instrumentation and set traces/profiles sample rates to 0 since codeflash is a CLI tool that doesn't need performance tracing. Error capturing (capture_exception, capture_message, LoggingIntegration) remains fully functional.
…arse_test_output Replace lazy `.*?` quantifiers in matches_re_start/matches_re_end with negated character classes (`[^:]`, `[^#]`, `[^.:]`) to eliminate quadratic backtracking. Replace per-line regex search for the pytest FAILURES header with a simple `"= FAILURES =" in line` string check. Add tests for the regex patterns and failure header detection.
Resolve project root paths once at construction time (TestConfig.__post_init__, FunctionOptimizer.__init__, filter_functions entry) instead of on every call to module_name_from_file_path — eliminating ~776 redundant filesystem syscalls.
StdlibIntegration in sentry-sdk 2.x doesn't accept subprocess_instrumentation as a parameter. Use disabled_integrations instead, which also avoids httplib patching overhead.
Drop .resolve() from ImportResolver, TestsCache, init_javascript, create_pr, and filter_functions where callers already pass resolved paths via CLI init or TestConfig.__post_init__.
…/codeflash-ai/codeflash into narrow-sentry-stdlib-integration
Drop .resolve() from ImportResolver, TestsCache, init_javascript, create_pr, and filter_functions where callers already pass resolved paths via CLI init or TestConfig.__post_init__. Also exclude test and fixture dirs from mypy to match ruff/ty config.
PR Review SummaryPrek Checks✅ Passed — Prek found 1 unused import ( Mypy
Code Review✅ No critical issues found in this re-review. Changes reviewed:
All 3 existing inline review comments already resolved (✅ Fixed). Test Coverage
Overall coverage: 78.59% → 78.61% (+0.02pp) — No regression. New file Note: 8 pre-existing test failures on both branches (7 in Last updated: 2026-02-19 |
Paths with .. segments (e.g. Path(__file__) / "../foo") don't match resolved file_path in module_name_from_file_path. Resolve once at the public entry point and pass down to the async variant. Also exclude test dirs from mypy config.
…istency On Windows, Path.resolve() can return 8.3 short names (e.g. RUNNER~1) that differ from long-name forms. Jedi returns resolved paths that may not match the project root's form, causing relative_to() failures. - Normalize Jedi definition paths through the project root via safe_relative_to to ensure consistent dict keys - Resolve both sides in is_project_path and module_name_from_file_path - Restore resolve in TestsCache for consistent cache keys
|
@claude fix the windows unit tests, fix the root cause |
…istency TestConfig.__post_init__ resolves project_root_path to long names, but FunctionToOptimize.file_path could retain Windows 8.3 short names (e.g., RUNNER~1 vs runneradmin), causing relative_to() failures. Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@claude fix the unit tests failures and push |
…olution FunctionToOptimize is a frozen Pydantic dataclass, so directly assigning to file_path raises FrozenInstanceError. Use dataclasses.replace() to create a new instance with the resolved path instead. Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com>
|
@claude fix the failing unit tests |
|
Claude finished @KRRT7's task in 7m 1s —— View job Fixing Failing Unit Tests
Root cause: Path mismatch in On Windows, Fix (commit
This ensures consistent path comparison regardless of Windows 8.3 name transformations. | |
…name consistency On Windows, tempfile.mkdtemp() returns paths with 8.3 short names while Jedi resolves to long-form paths. The dict lookup for original_helper_code failed silently, causing unused helpers to never be reverted. Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ration perf: remove redundant project_root_path.resolve() from hot path
Summary
project_root_pathandtests_project_rootdironce at construction time (TestConfig.__post_init__) instead of on every call tomodule_name_from_file_path.resolve()syscall frommodule_name_from_file_path— eliminating ~776 filesystem syscalls from the hot pathFunctionOptimizer.__init__andfilter_functionsentry to ensure consistency with symlink-canonical pathsTest plan
pytest tests/test_code_utils.py -k module_name_from_file_path— 4 passpytest tests/test_async_function_discovery.py::test_get_functions_to_optimize_with_async— passpytest tests/test_formatter.py::test_formatting_file_with_many_diffs— passpytest tests/test_function_discovery.py::test_filter_functions_tests_root_overlaps_source— pass