Commit graph

7464 commits

Author SHA1 Message Date
Kevin Turcios
d8fbca01bc feat: add --trace-tests mode for optimizing via existing unit tests
Enables CodeFlash to use existing unit tests as both a source of function
invocations (for replay test generation) and as the performance baseline
(for end-to-end speedup reporting). Traces top-15 ranked functions via
unit tests, optimizes with high effort, and measures per-function speedup.
2026-03-20 01:16:37 -06:00
Saurabh Misra
59031a145e
Merge pull request #1874 from codeflash-ai/java-tracer
feat: Java tracing agent with end-to-end optimization pipeline
2026-03-19 15:12:11 -07:00
misrasaurabh1
3b396578d7 make workload purposefully terrible 2026-03-19 12:22:26 -07:00
misrasaurabh1
3bf8ffb76a chore: remove accidental package-lock.json and package.json
These files were unrelated to the PR and got swept in during a
stash/pop operation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 11:48:03 -07:00
Sarthak Agarwal
668c6d895d
Merge pull request #1878 from codeflash-ai/fix/bug_lang_detection
fix on singleton class returning python as current lang always
2026-03-20 00:16:42 +05:30
claude[bot]
54020888e7
Merge pull request #1876 from codeflash-ai/codeflash/optimize-pr1874-2026-03-19T08.11.52
️ Speed up method `JfrProfile._parse_json` by 42% in PR #1874 (`java-tracer`)
2026-03-19 18:42:41 +00:00
misrasaurabh1
fa1ed76e88 fix: address review feedback — dedup parser, error on missing command, filter empty names
- Consolidate _parse_replay_metadata to call parse_replay_test_metadata
  instead of duplicating the parsing logic
- Replace hardcoded fallback java command with a clear error message
  when no java command is provided
- Filter empty strings from function_names split (\"".split(\",\")
  returns [\"\"] which is truthy)
- Fix import ordering in tracer.py (ruff I001)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 11:37:15 -07:00
claude[bot]
0a71905be8 test: update git_diff tests to match new all-extensions behavior
get_git_diff now uses all registered extensions instead of filtering
by current language, so update tests to reflect the new behavior.

Co-authored-by: Sarthak Agarwal <undefined@users.noreply.github.com>
2026-03-19 18:07:19 +00:00
claude[bot]
44e83a4a85 style: auto-fix ruff formatting in get_git_diff signature
Co-authored-by: Sarthak Agarwal <undefined@users.noreply.github.com>
2026-03-19 18:05:29 +00:00
Sarthak Agarwal
3abe4e959d
Update git_utils.py 2026-03-19 23:29:52 +05:30
Sarthak Agarwal
9aa77bd6c1 fix on singleton class returning python as current lang always 2026-03-19 23:27:10 +05:30
codeflash-ai[bot]
0cf1d1b951
Optimize JfrProfile._parse_json
The optimization precomputes all frame-to-key conversions for a stack trace once (into a `keys` list) instead of calling `_frame_to_key` repeatedly inside the caller-callee loop, cutting per-frame extraction from ~3.3 µs to ~0.19 µs (83% reduction) and lifting `_frame_to_key` from 20.8% of total time to 43.2% (the loop cost is now dominated by the upfront list comprehension rather than repeated calls). A local `matches_packages_cached` closure memoizes package-filter results to avoid re-checking the same method keys across caller relationships, reducing `_matches_packages` overhead from 12.6% to 0.8% of total time; profiler data shows `_matches_packages` hits dropped from 18,364 to 1,500. The timestamp-duration calculation switched from accumulating a list then calling `max()`/`min()` to inline min/max tracking, removing intermediate allocations; combined, these changes yield a 42% overall speedup (46.4 ms → 32.6 ms).
2026-03-19 08:11:56 +00:00
misrasaurabh1
d12e631ce9 add some initial java docs 2026-03-19 00:44:29 -07:00
Kevin Turcios
0827611b10
Merge pull request #1860 from codeflash-ai/fix/attrs-init-instrumentation
fix: instrument attrs classes in __init__ capture (crash fix + monkey-patch wrapper)
2026-03-19 01:24:04 -06:00
claude[bot]
55c6d29918 fix: resolve mypy type errors in Java tracer, jfr_parser, and function_ranker
- Import Language from codeflash.languages (exported) not codeflash.languages.base
- Fix _detect_non_python_language return type: object | None -> Language | None
- Fix bare dict type annotations: dict -> dict[str, Any] in jfr_parser.py and function_ranker.py
- Fix pytest_splits/test_paths type narrowing by separating assignment from None check

Co-authored-by: Saurabh Misra <undefined@users.noreply.github.com>
2026-03-19 07:13:16 +00:00
misrasaurabh1
5d8ca3bd85 fix: timeout handling and block comment parsing for Java tracer
- Read --timeout from both config.timeout and config.tracer_timeout
- Handle multi-line /* */ block comments in package detection (aerospike
  source files start with license block comments before package declaration)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 00:05:17 -07:00
Saurabh Misra
59f34d8752
Merge pull request #1875 from codeflash-ai/codeflash/optimize-pr1874-2026-03-19T06.41.55
️ Speed up method `JavaFunctionRanker.get_function_addressable_time` by 1,245% in PR #1874 (`java-tracer`)
2026-03-18 23:49:54 -07:00
codeflash-ai[bot]
d589aa0a1b
Optimize JavaFunctionRanker.get_function_addressable_time
The original code performed a linear scan over `self._ranking` on every call to `get_function_addressable_time`, which `rank_functions` invokes repeatedly (once per function to filter, plus once per function to sort). The optimized version builds a hash map `_ranking_by_name` during `__init__`, replacing the O(n) loop with an O(1) dictionary lookup. Line profiler confirms the loop and comparison accounted for 94.7% of original runtime. When `rank_functions` calls `get_function_addressable_time` dozens or hundreds of times across a 1000-method ranking (as in `test_large_number_of_methods_and_repeated_queries_perf_and_correctness`), the lookup cost drops from ~293 µs to ~10 µs per call, yielding the 1244% overall speedup. The optimization also consolidates the two calls to `get_addressable_time_ns` in `get_function_stats_summary` into a single call, stored in a local variable, eliminating redundant work.
2026-03-19 06:41:58 +00:00
claude[bot]
d5ca52af88 style: fix ruff formatting and revert auto-generated version
- Unwrap logger.info call in tracer.py that fits within 120-char limit
- Revert auto-generated dev version string in version.py back to 0.20.3

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-19 06:29:35 +00:00
misrasaurabh1
c31f83726a fix: ensure src/test/java directory exists before config validation
Git doesn't track empty directories, so src/test/java must be created
before process_pyproject_config validates tests-root exists.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 23:19:44 -07:00
misrasaurabh1
0a83002555 fix: Java tracer e2e test script for CI compatibility
- Use `uv run -m codeflash.main` instead of direct file path
- Remove redundant --no-pr (already hardcoded in _run_java_tracer)
- Clean up leftover replay tests between retry attempts
- Add error logging for subprocess output

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 23:17:27 -07:00
misrasaurabh1
c699093a26 Initial e2e tracer implementation 2026-03-18 23:03:35 -07:00
Kevin Turcios
cb2cbafe2c
Merge pull request #1873 from codeflash-ai/fix/claude-gha-review-improvements
fix: improve Claude GHA review behavior
2026-03-18 19:07:35 -06:00
Kevin Turcios
f4319aac67 fix: scale review depth to PR size, add scope boundaries
- Triage now classifies PRs as TRIVIAL/SMALL/LARGE based on lines changed
- SMALL PRs: focused correctness check, quick duplicate scan, skip coverage
- LARGE PRs: full review with design checks, deep duplicate detection, coverage
- Optimization PRs: concise correctness verdict instead of long essays
- Added explicit scope rules: only read files in the diff, don't explore broadly
2026-03-18 19:06:40 -06:00
Kevin Turcios
f1cf46ce6b fix: improve Claude GHA review behavior
- Stop closing PRs on unrelated CI failures (check base branch first)
- Remove age-only auto-close rule; require individual evaluation
- Prevent mass-closing without per-PR analysis
- Merge conflicts only close after 3 days (not immediately)
- Resolve stale threads silently (no " Fixed" reply noise)
- Add design review checks (module placement, root cause, config files)
- Flag accidental file inclusions (binaries, auto-generated versions)
- Request tests for untested new public functions
2026-03-18 19:01:18 -06:00
Kevin Turcios
6d897cd4e3 fix: remove overwrite of language-specific extensions in get_git_diff
Line 42 was overwriting the current language's file_extensions with all
registered extensions, causing Java files to appear in Python-only diffs.
2026-03-18 18:44:39 -06:00
Kevin Turcios
8ec5eee4f4 fix: use string literals in cast() to satisfy TC006 ruff rule 2026-03-18 18:36:35 -06:00
claude[bot]
01d8fafabb fix: add cast to resolve mypy list covariance errors in _build_attrs_patch_block
Co-authored-by: Kevin Turcios <undefined@users.noreply.github.com>
2026-03-19 00:18:27 +00:00
Kevin Turcios
aae0171b1c Merge branch 'main' into fix/attrs-init-instrumentation 2026-03-18 18:14:33 -06:00
HeshamHM28
030df218be
Merge pull request #1774 from codeflash-ai/feat/gradle-executor-from-java
feat: add Gradle build tool support for Java optimization
2026-03-18 23:00:25 +02:00
claude[bot]
4c9abfb2aa refactor: remove redundant try/finally; rely on conftest autouse fixture for language cleanup
The conftest.py autouse fixture already resets _current_language before/after
each test, making per-test try/finally cleanup unnecessary.

Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com>
2026-03-18 18:23:49 +00:00
claude[bot]
0672e11342 fix: reset language singleton in test to prevent cross-test pollution
test_parse_line_profile_results_non_python_java_json set Language.JAVA
but never reset it, causing test_java_diff_ignored_when_language_is_python
to fail when tests ran in this order.

Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com>
2026-03-18 17:34:03 +00:00
claude[bot]
c1b8029667
Merge pull request #1867 from codeflash-ai/codeflash/optimize-pr1860-2026-03-18T10.39.52
️ Speed up method `InitDecorator.visit_ClassDef` by 10% in PR #1860 (`fix/attrs-init-instrumentation`)
2026-03-18 13:37:18 +00:00
Sarthak Agarwal
32decd746c
Merge pull request #1858 from codeflash-ai/fix/add_lang_ext_support_to_diff
add_lang_ext_support_to_diff
2026-03-18 18:45:09 +05:30
claude[bot]
46016bddf0
Merge pull request #1866 from codeflash-ai/codeflash/optimize-pr1860-2026-03-18T10.30.36
️ Speed up method `InitDecorator.visit_Module` by 12% in PR #1860 (`fix/attrs-init-instrumentation`)
2026-03-18 10:43:50 +00:00
codeflash-ai[bot]
5a795be92f
Optimize InitDecorator.visit_ClassDef
The optimization eliminates redundant iterations through `node.body` by adding a `break` statement immediately after finding and decorating the `__init__` method (when `has_init=True`). The profiler shows the outer body loop dropped from 392 hits to 376 hits (~4% fewer), and the inner decorator-list loop dropped from 18 hits to 18 hits but now exits cleanly via `break` instead of continuing to scan remaining body items. Additionally, the `if not has_init:` branch now consolidates dataclass/attrs/NamedTuple checks in a single decorator loop instead of three separate passes, reducing `_expr_name` calls from 471 total hits to 263 (~44% fewer) and cutting that function's time from 391 µs to 218 µs. Runtime improved from 405 µs to 367 µs (10% faster) with no correctness regressions across all test cases.
2026-03-18 10:39:56 +00:00
codeflash-ai[bot]
e66d7c187a
Optimize InitDecorator.visit_Module
The optimization pre-parses the `codeflash_capture` import statement once in `__init__` and stores it in `self._import_stmt`, eliminating the repeated `ast.parse` call inside `visit_Module`. Line profiler confirms the original code spent ~186 µs (1% of runtime) parsing the import on every module visit (11 hits × 16.9 µs each), which is now reduced to a one-time ~8 µs insertion cost. This reduces total `visit_Module` time by ~2.6% (17.87 ms → 17.41 ms) with no correctness trade-offs, preserving all AST structure and behavior across diverse test scenarios including large modules with 100+ classes.
2026-03-18 10:30:40 +00:00
Kevin Turcios
9fae3949b9
Update codeflash/languages/python/context/code_context_extractor.py
Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
2026-03-18 04:13:55 -06:00
claude[bot]
d7323ed3f2 style: collapse single-line if in _build_attrs_patch_block per ruff-format
Co-Authored-By: Kevin Turcios <undefined@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 09:47:26 +00:00
Kevin Turcios
115cdba481 fix: address review feedback for attrs init instrumentation
- Fix bug: skip attrs classes with init=False (no __init__ to patch)
- Deduplicate attrs namespace/name sets into shared constants
- Fix _get_attrs_config to resolve import aliases properly
- Add test for init=False case with exact expected output
2026-03-18 03:34:44 -06:00
Kevin Turcios
1f2027c731
️ Speed up InitDecorator._build_attrs_patch_block by 40%
️ Speed up method `InitDecorator._build_attrs_patch_block` by 40% in PR #1860 (`fix/attrs-init-instrumentation`)
2026-03-18 03:22:39 -06:00
codeflash-ai[bot]
fefdd4c9cf
Optimize InitDecorator._build_attrs_patch_block
The optimization pre-allocates reusable AST node fragments in `__init__` (such as `ast.Load()`, `ast.Store()`, `ast.Name(id="self")`, and `ast.Starred`) that previously were reconstructed on every call to `_build_attrs_patch_block`. Because AST nodes are immutable value objects that Python interns, referencing the same instances avoids repeated allocation overhead—profiler data shows lines constructing `ast.Name`, `ast.arg`, and `ast.Starred` nodes dropped from ~1–3 µs each to ~0.1–0.4 µs. Across 2868 invocations (per profiler), this yields the observed 40% runtime reduction from 22.7 ms to 16.2 ms with no correctness regressions.
2026-03-18 09:00:20 +00:00
claude[bot]
e94e0fcff9 style: auto-fix ruff formatting in instrument_codeflash_capture.py
Co-authored-by: Kevin Turcios <undefined@users.noreply.github.com>
2026-03-18 07:51:36 +00:00
Kevin Turcios
0cb8a08c7e feat: instrument attrs __init__ via module-level monkey-patch wrapper
Instead of skipping attrs classes entirely (previous approach), emit a
module-level patch block immediately after the class definition:

  _codeflash_orig_ClassName_init = ClassName.__init__
  def _codeflash_patched_ClassName_init(self, *args, **kwargs):
      return _codeflash_orig_ClassName_init(self, *args, **kwargs)
  ClassName.__init__ = codeflash_capture(...)(_codeflash_patched_ClassName_init)

This sidesteps the __class__ cell TypeError that attrs(slots=True) triggers
when a synthetic super().__init__() body is injected into the original class,
because the patched wrapper is a plain module-level function with no __class__
cell.

Changes:
- InitDecorator.__init__: add _attrs_classes_to_patch dict
- visit_ClassDef: for attrs classes, record (name -> decorator) instead of
  returning immediately; set inserted_decorator=True
- visit_Module: splice patch block statements after each attrs ClassDef
- _build_attrs_patch_block: new helper that builds the 3-statement AST block
- Tests: rename *_no_init_skipped -> *_patched_via_module_wrapper and update
  expected strings to assert the exact generated patch block

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-03-18 01:42:29 -06:00
Kevin Turcios
dd5e347bbb fix: skip attrs classes in __init__ instrumentation; add attrs support to code_context_extractor
- instrument_codeflash_capture: detect @attrs.define / @attr.s / etc. in the
  'no explicit __init__' branch and return early, same as dataclass/NamedTuple.
  Prevents a TypeError caused by attrs(slots=True) creating a new class whose
  __class__ cell no longer matches the injected super().__init__ wrapper.

- code_context_extractor: add _get_attrs_config() helper; update
  _collect_synthetic_constructor_type_names, _build_synthetic_init_stub, and
  _extract_synthetic_init_parameters to handle attrs field conventions
  (factory= keyword, init=False, kw_only).

- tests: add 3 exact-output tests for instrumentation skip behaviour and
  3 exact-output tests for attrs stub generation.

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-03-18 01:33:40 -06:00
HeshamHM28
dd20db20a1 fix setup_test_config 2026-03-18 06:28:55 +02:00
HeshamHM28
2a35716864
Merge branch 'main' into feat/gradle-executor-from-java 2026-03-18 06:14:47 +02:00
HeshamHM28
ba36a1f7b2 fix jar file problems 2026-03-18 05:47:56 +02:00
HeshamHM28
6b2a852d79 fix running tests 2026-03-18 05:29:00 +02:00
HeshamHM28
cd0e19396c fix multi_root 2026-03-18 04:24:16 +02:00