Skip to content

feat: support void method optimization in Java pipeline#1980

Draft
HeshamHM28 wants to merge 4 commits intomainfrom
cf-java-void-optimization
Draft

feat: support void method optimization in Java pipeline#1980
HeshamHM28 wants to merge 4 commits intomainfrom
cf-java-void-optimization

Conversation

@HeshamHM28
Copy link
Copy Markdown
Contributor

Summary

  • Fix Java void method instrumentation to generate compilable code for both static and instance void methods
  • For static void calls (e.g., InPlaceSorter.bubbleSortInPlace(arr)), serialize the arguments instead of the class name, which is not a value and can't be cast to Object
  • For instance void calls (e.g., sorter.bubbleSortInPlace(arr)), serialize the receiver object to capture side effects
  • Add void-specific discovery, comparison, and assert-removal support across the Java pipeline
  • Add e2e test and CI workflow for void function optimization

HeshamHM28 and others added 2 commits April 2, 2026 11:55
Discover void methods, instrument them by serializing the receiver instead
of a return value, and treat all-null comparisons as equivalent.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the workflow-modified This PR modifies GitHub Actions workflows label Apr 3, 2026
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 3, 2026

Claude finished @HeshamHM28's task in 8m 20s —— View job


PR Review Summary

Prek Checks

All prek checks pass (ruff, format). No issues.

Mypy reports 2 errors in codeflash/discovery/functions_to_optimize.py:200 — these are pre-existing (wrong call signature for discover_functions(file_path, criteria) vs (source, file_path, criteria)) and were not introduced by this PR.


Code Review

🔴 Version Regression

codeflash/version.py is downgraded from 0.20.50.20.4. This looks like a rebase artifact from branching off an older commit. This needs to be reverted before merging. Fix this →

🟡 Latent Bug: remove_assertions_from_test ignores target_return_type

remove_asserts.py:1307 — the remove_assertions_from_test convenience wrapper calls transform_java_assertions without target_return_type:

def remove_assertions_from_test(source: str, target_function: FunctionToOptimize) -> str:
    return transform_java_assertions(
        source=source, function_name=target_function.function_name, qualified_name=target_function.qualified_name
        # target_return_type missing!
    )

For void methods, this means _generate_replacement will attempt to emit void result = method(); instead of a bare call — a Java compilation error. This function isn't called in production code today, but it's exported from __init__.py and will cause issues if used. Fix this →

🟡 Dead code: non-precise void path generates invalid Java

instrumentation.py:439–440 — when precise_call_timing=False and is_void=True:

elif is_void:
    replacement = f"{bare_call_stmt} {serialize_stmt}"

serialize_stmt references _cf_serializedResult{iter_id} which is never declared in the non-precise path, so this would produce a Java compilation error if reached. This path is currently unreachable since wrap_target_calls_with_treesitter is only ever called with precise_call_timing=True, but it should either be removed or the variable declaration added.

🟡 Fragile static-call heuristic

instrumentation.py:356:

is_static_call = receiver != "this" and receiver[:1].isupper()

This will misidentify all-caps constant instance fields (e.g., SOME_SERVICE.sort(arr) where SOME_SERVICE is a singleton, not a class name) as static calls, silently skipping receiver-state capture. Same pattern is used in test_discovery.py for consistency, but worth documenting the known limitation.


Duplicate Detection

No duplicates detected. The uppercase-first-char heuristic for static call detection is consistently used across test_discovery.py and instrumentation.py — it's not a duplicate, it's intentionally shared logic.


Test Coverage

instrumentation.py: 83% coverage from the new tests — good.

The 3 new void-specific test cases in test_instrumentation.py cover:

  • Instance void method serialization (receiver + args)
  • Static void method serialization (args only)
  • Implicit this receiver for void calls with no explicit receiver

remove_asserts.py and functions_to_optimize.py coverage is low (12%) but expected since only instrumentation tests were run. The new test_void_discovery_with_require_return_false test covers the discovery change.


Optimization PRs

PR #1954 (⚡️ Speed up TestResults.total_passed_runtime by 20%) — skipped: has merge conflicts but is only 2 days old (created 2026-04-01), under the 3-day threshold.


Last updated: 2026-04-03

@codeflash-ai
Copy link
Copy Markdown
Contributor

codeflash-ai bot commented Apr 3, 2026

⚡️ Codeflash found optimizations for this PR

📄 25% (0.25x) speedup for JavaAssertTransformer._generate_replacement in codeflash/languages/java/remove_asserts.py

⏱️ Runtime : 886 microseconds 708 microseconds (best of 250 runs)

A dependent PR with the suggested changes has been created. Please review:

If you approve, it will be merged into this PR (branch cf-java-void-optimization).

Static Badge

claude bot added a commit that referenced this pull request Apr 3, 2026
…2026-04-03T13.47.39

⚡️ Speed up method `JavaAssertTransformer._generate_replacement` by 25% in PR #1980 (`cf-java-void-optimization`)
@codeflash-ai
Copy link
Copy Markdown
Contributor

codeflash-ai bot commented Apr 3, 2026

@HeshamHM28 HeshamHM28 force-pushed the cf-java-void-optimization branch from 10cfedf to 3bc4941 Compare April 3, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

workflow-modified This PR modifies GitHub Actions workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant