Skip to content

⚡️ Speed up function _extract_gradle_include_modules by 22% in PR #1906 (cf-java-zero-config-strategy)#1908

Merged
mashraf-222 merged 1 commit intocf-java-zero-config-strategyfrom
codeflash/optimize-pr1906-2026-03-26T12.05.22
Mar 26, 2026
Merged

⚡️ Speed up function _extract_gradle_include_modules by 22% in PR #1906 (cf-java-zero-config-strategy)#1908
mashraf-222 merged 1 commit intocf-java-zero-config-strategyfrom
codeflash/optimize-pr1906-2026-03-26T12.05.22

Conversation

@codeflash-ai
Copy link
Copy Markdown
Contributor

@codeflash-ai codeflash-ai bot commented Mar 26, 2026

⚡️ This pull request contains optimizations for PR #1906

If you approve this dependent PR, these changes will be merged into the original PR branch cf-java-zero-config-strategy.

This PR will be automatically closed if the original PR is merged.


📄 22% (0.22x) speedup for _extract_gradle_include_modules in codeflash/languages/java/gradle_strategy.py

⏱️ Runtime : 2.58 milliseconds 2.12 milliseconds (best of 221 runs)

📝 Explanation and details

Pre-compiling the two regex patterns (_RE_INCLUDE and _RE_QUOTED) at module load time eliminates the per-call compilation overhead that re.finditer and re.findall incurred when given raw strings. Line profiler shows the inner loop's regex overhead dropped from ~3.4 ms to ~1.8 ms (47% reduction), and the outer loop regex from ~1.8 ms to ~1.1 ms (39% reduction), yielding a 21% overall speedup. The optimization is particularly effective in the realistic _parse_gradle_settings_modules caller, where the function may be invoked repeatedly across many project roots. No functional or behavioral changes; all tests pass with identical outputs.

Correctness verification report:

Test Status
⚙️ Existing Unit Tests 🔘 None Found
🌀 Generated Regression Tests 76 Passed
⏪ Replay Tests 🔘 None Found
🔎 Concolic Coverage Tests 🔘 None Found
📊 Tests Coverage 100.0%
🌀 Click to see Generated Regression Tests
from codeflash.languages.java.gradle_strategy import _extract_gradle_include_modules


def test_single_include_with_parentheses_and_commas():
    # A typical include with parentheses and multiple single-quoted modules
    content = "include(':app', ':lib', ':core')"
    # Expect leading colons stripped from each module name
    assert _extract_gradle_include_modules(content) == ["app", "lib", "core"]  # 7.16μs -> 5.66μs (26.6% faster)


def test_include_without_parentheses_and_mixed_quotes():
    # Gradle also allows include without parentheses and with double quotes
    content = "include \":one\", ':two'\n"
    # The function should find both quoted module names regardless of quote style
    assert _extract_gradle_include_modules(content) == ["one", "two"]  # 6.67μs -> 5.36μs (24.5% faster)


def test_multiple_include_directives_on_multiple_lines():
    # Multiple include directives across the file should all be captured
    content = """
    include(':a', ':b')
    someOtherSetting = true
    include ':c'
    include(":d", ":e")
    """
    # Order is preserved in the order of appearance
    assert _extract_gradle_include_modules(content) == ["a", "b", "c", "d", "e"]  # 10.3μs -> 8.21μs (24.9% faster)


def test_empty_input_returns_empty_list():
    # No content should result in no modules found
    assert _extract_gradle_include_modules("") == []  # 2.50μs -> 1.66μs (50.6% faster)


def test_no_include_in_content_returns_empty_list():
    # Content contains quotes but no include() directive
    content = 'someVar = ":not_module"\nprintln("done")'
    # Should not extract anything since there is no include(...)
    assert _extract_gradle_include_modules(content) == []  # 2.48μs -> 1.74μs (42.6% faster)


def test_leading_colon_only_is_ignored():
    # include(':') yields an empty module name after lstrip and must be skipped
    content = "include(':')"
    assert _extract_gradle_include_modules(content) == []  # 6.00μs -> 4.81μs (24.8% faster)


def test_empty_quoted_string_is_ignored_among_valid_entries():
    # Mixed valid and empty quotes: empty quoted string should be ignored
    content = "include('', ':valid', \"\")"
    assert _extract_gradle_include_modules(content) == ["valid"]  # 6.58μs -> 5.39μs (22.1% faster)


def test_module_names_with_internal_colons_and_special_chars_are_preserved():
    # Internal colons should be preserved (e.g., nested modules a:b), only leading colon removed
    content = "include(':a:b', ':complex-module_1.2')"
    assert _extract_gradle_include_modules(content) == ["a:b", "complex-module_1.2"]  # 6.85μs -> 5.51μs (24.4% faster)


def test_handles_nested_project_call_style_and_parentheses_content():
    # include(project(':foo')) style: the regex should still find the quoted ':foo'
    content = "include(project(':foo'))"
    assert _extract_gradle_include_modules(content) == ["foo"]  # 6.23μs -> 4.76μs (31.0% faster)


def test_quotes_elsewhere_not_following_include_are_ignored():
    # Quoted strings that are not arguments to include() should not be extracted
    content = 'println("hello")\ninclude(":x")\nval = ":y"'
    # Only the include(":x") should be considered
    assert _extract_gradle_include_modules(content) == ["x"]  # 6.22μs -> 4.68μs (33.0% faster)


def test_include_with_comments_inside_parentheses_does_not_break_parsing():
    # Comments inside parentheses (Java style) are not special-cased by this function,
    # but quoted module names should still be found as long as quotes are present.
    content = "include( /* comment */ ':c' /* another */ )"
    assert _extract_gradle_include_modules(content) == ["c"]  # 6.61μs -> 5.20μs (27.2% faster)


def test_large_number_of_modules_in_single_include_parentheses():
    # Create 1000 module names and a single include(...) line containing them all
    count = 1000
    modules = [f"m{i}" for i in range(count)]
    # Build a single include line with each module quoted and prefixed by a colon
    content = "include(" + ", ".join(f"':{m}'" for m in modules) + ")"
    result = _extract_gradle_include_modules(content)  # 337μs -> 338μs (0.411% slower)
    # Verify the result length and the exact ordering and values
    assert len(result) == count
    assert result == modules  # exact match in order


def test_many_include_directives_with_one_module_each():
    # Create 1000 lines each with a single include of one module
    count = 1000
    modules = [f"pkg{i}" for i in range(count)]
    content_lines = [f"include(':{m}')" for m in modules]
    content = "\n".join(content_lines)
    result = _extract_gradle_include_modules(content)  # 1.00ms -> 706μs (41.8% faster)
    # Should extract all modules in document order
    assert result == modules


def test_various_whitespace_and_tab_formats():
    # Whitespace variations around include, parentheses, and commas should be tolerated
    content = "include (  ':a' ,\t':b'\n)\ninclude:':c'"
    # The last token "include:':c'" is not a valid include directive and should not match,
    # but the two valid include calls should produce 'a' and 'b'
    assert _extract_gradle_include_modules(content) == ["a", "b"]  # 8.61μs -> 6.89μs (24.9% faster)


def test_include_arguments_spanning_to_newline_only_capture_before_newline():
    content = "include(':first',\n':second')\ninclude(':third')"
    result = _extract_gradle_include_modules(content)  # 7.88μs -> 6.16μs (28.0% faster)
    assert result == ["first", "third"]
# imports
from codeflash.languages.java.gradle_strategy import _extract_gradle_include_modules

# ============================================================================
# BASIC TESTS — Verify fundamental functionality under normal conditions
# ============================================================================


def test_basic_single_module_with_double_quotes():
    """Test extraction of a single module with double quotes."""
    content = 'include("app")'
    result = _extract_gradle_include_modules(content)  # 6.73μs -> 5.32μs (26.6% faster)
    assert result == ["app"]


def test_basic_single_module_with_single_quotes():
    """Test extraction of a single module with single quotes."""
    content = "include('app')"
    result = _extract_gradle_include_modules(content)  # 6.15μs -> 4.67μs (31.8% faster)
    assert result == ["app"]


def test_basic_multiple_modules_comma_separated():
    """Test extraction of multiple modules separated by commas."""
    content = 'include("app", "lib")'
    result = _extract_gradle_include_modules(content)  # 6.67μs -> 5.17μs (29.1% faster)
    assert result == ["app", "lib"]


def test_basic_multiple_modules_mixed_quotes():
    """Test extraction of multiple modules with mixed quote types."""
    content = "include(\"app\", 'lib')"
    result = _extract_gradle_include_modules(content)  # 6.44μs -> 5.01μs (28.6% faster)
    assert result == ["app", "lib"]


def test_basic_module_with_colon_prefix():
    """Test extraction where module name has leading colon (should be stripped)."""
    content = 'include(":app")'
    result = _extract_gradle_include_modules(content)  # 6.04μs -> 4.69μs (28.9% faster)
    assert result == ["app"]


def test_basic_module_with_nested_path():
    """Test extraction of module with nested path structure."""
    content = 'include("app:features:payments")'
    result = _extract_gradle_include_modules(content)  # 6.27μs -> 4.85μs (29.3% faster)
    assert result == ["app:features:payments"]


def test_basic_multiple_modules_with_nested_paths():
    """Test extraction of multiple modules with nested paths."""
    content = 'include("app:features", "lib:core")'
    result = _extract_gradle_include_modules(content)  # 6.73μs -> 5.36μs (25.6% faster)
    assert result == ["app:features", "lib:core"]


def test_basic_include_with_parentheses():
    """Test extraction with explicit parentheses in include statement."""
    content = 'include("app")'
    result = _extract_gradle_include_modules(content)  # 5.87μs -> 4.51μs (30.2% faster)
    assert result == ["app"]


def test_basic_include_without_parentheses():
    """Test extraction when parentheses are optional (space after include)."""
    content = 'include "app"'
    result = _extract_gradle_include_modules(content)  # 5.97μs -> 4.58μs (30.4% faster)
    assert result == ["app"]


def test_basic_multiple_includes_in_content():
    """Test extraction when multiple include statements exist."""
    content = """
    include("app")
    include("lib")
    """
    result = _extract_gradle_include_modules(content)  # 7.79μs -> 6.15μs (26.6% faster)
    assert result == ["app", "lib"]


def test_basic_multiple_includes_with_multiple_modules_each():
    """Test extraction with multiple include statements each having multiple modules."""
    content = """
    include("app", "features")
    include("lib", "core")
    """
    result = _extract_gradle_include_modules(content)  # 8.80μs -> 6.90μs (27.5% faster)
    assert result == ["app", "features", "lib", "core"]


def test_basic_whitespace_around_include():
    """Test that whitespace around include keyword is handled correctly."""
    content = '  include ( "app" )  '
    result = _extract_gradle_include_modules(content)  # 5.86μs -> 4.57μs (28.3% faster)
    assert result == ["app"]


def test_basic_module_names_with_underscores():
    """Test extraction of module names containing underscores."""
    content = 'include("my_app", "test_lib")'
    result = _extract_gradle_include_modules(content)  # 6.46μs -> 5.19μs (24.5% faster)
    assert result == ["my_app", "test_lib"]


def test_basic_module_names_with_hyphens():
    """Test extraction of module names containing hyphens."""
    content = 'include("my-app", "test-lib")'
    result = _extract_gradle_include_modules(content)  # 6.41μs -> 5.14μs (24.8% faster)
    assert result == ["my-app", "test-lib"]


def test_basic_module_names_with_numbers():
    """Test extraction of module names containing numbers."""
    content = 'include("app2", "lib3v1")'
    result = _extract_gradle_include_modules(content)  # 6.29μs -> 5.12μs (22.9% faster)
    assert result == ["app2", "lib3v1"]


def test_basic_preserves_order():
    """Test that the function preserves the order of modules."""
    content = 'include("zebra", "apple", "middle")'
    result = _extract_gradle_include_modules(content)  # 6.75μs -> 5.49μs (23.0% faster)
    assert result == ["zebra", "apple", "middle"]


# ============================================================================
# EDGE TESTS — Evaluate behavior under extreme or unusual conditions
# ============================================================================


def test_edge_empty_string():
    """Test with empty input string."""
    content = ""
    result = _extract_gradle_include_modules(content)  # 2.45μs -> 1.68μs (45.8% faster)
    assert result == []


def test_edge_no_include_statements():
    """Test with content that has no include statements."""
    content = "println 'hello world'"
    result = _extract_gradle_include_modules(content)  # 2.54μs -> 1.73μs (46.9% faster)
    assert result == []


def test_edge_include_with_empty_quotes():
    """Test include statement with empty quotes (should be skipped)."""
    content = 'include("")'
    result = _extract_gradle_include_modules(content)  # 5.14μs -> 3.76μs (36.8% faster)
    assert result == []


def test_edge_include_with_only_colon():
    """Test include statement where module is only colon after lstrip."""
    content = 'include(":")'
    result = _extract_gradle_include_modules(content)  # 6.03μs -> 4.60μs (31.2% faster)
    assert result == []


def test_edge_multiple_colons_prefix():
    """Test module name with multiple leading colons."""
    content = 'include(":::app")'
    result = _extract_gradle_include_modules(content)  # 5.96μs -> 4.73μs (26.1% faster)
    assert result == ["app"]


def test_edge_newline_in_include_args():
    """Test that newlines in include arguments are not matched."""
    content = """include("app"
    "lib")"""
    result = _extract_gradle_include_modules(content)  # 6.10μs -> 4.69μs (30.1% faster)
    # The regex should stop at newline, so only "app" is captured
    assert result == ["app"]


def test_edge_quoted_string_with_spaces():
    """Test module name containing spaces within quotes."""
    content = 'include("my app")'
    result = _extract_gradle_include_modules(content)  # 5.89μs -> 4.66μs (26.4% faster)
    assert result == ["my app"]


def test_edge_deeply_nested_module_path():
    """Test module with very deeply nested path structure."""
    content = 'include("a:b:c:d:e:f:g:h")'
    result = _extract_gradle_include_modules(content)  # 6.13μs -> 4.79μs (28.0% faster)
    assert result == ["a:b:c:d:e:f:g:h"]


def test_edge_single_character_module_name():
    """Test extraction of single character module names."""
    content = 'include("a", "b", "x")'
    result = _extract_gradle_include_modules(content)  # 6.59μs -> 5.28μs (24.9% faster)
    assert result == ["a", "b", "x"]


def test_edge_very_long_module_name():
    """Test extraction of very long module name."""
    long_name = "a" * 500
    content = f'include("{long_name}")'
    result = _extract_gradle_include_modules(content)  # 14.9μs -> 13.4μs (11.7% faster)
    assert result == [long_name]


def test_edge_special_chars_in_module_name():
    """Test module names with dots and underscores (common in Java)."""
    content = 'include("com.example.app", "org_apache_lib")'
    result = _extract_gradle_include_modules(content)  # 6.98μs -> 5.71μs (22.3% faster)
    assert result == ["com.example.app", "org_apache_lib"]


def test_edge_mixed_quote_delimiters_in_same_call():
    """Test that different quote types don't interfere with parsing."""
    content = 'include("app1", \'app2\', "app3")'
    result = _extract_gradle_include_modules(content)  # 6.94μs -> 5.56μs (24.9% faster)
    assert result == ["app1", "app2", "app3"]


def test_edge_include_with_extra_spaces():
    """Test include with extra spaces between keyword and parentheses."""
    content = 'include    (  "app"  )'
    result = _extract_gradle_include_modules(content)  # 5.96μs -> 4.61μs (29.4% faster)
    assert result == ["app"]


def test_edge_content_with_comments():
    """Test that Gradle comments don't break extraction (not actual parsing)."""
    content = """
    // include("commented")
    include("active")
    """
    result = _extract_gradle_include_modules(content)  # 8.03μs -> 6.29μs (27.6% faster)
    # Both will be matched by the regex since it's a simple pattern
    assert "active" in result


def test_edge_include_statement_at_start():
    """Test include statement at the very start of content."""
    content = 'include("first")\ninclude("second")'
    result = _extract_gradle_include_modules(content)  # 7.51μs -> 6.09μs (23.3% faster)
    assert result == ["first", "second"]


def test_edge_include_statement_at_end():
    """Test include statement at the very end of content."""
    content = 'some code\ninclude("last")'
    result = _extract_gradle_include_modules(content)  # 5.90μs -> 4.56μs (29.5% faster)
    assert result == ["last"]


def test_edge_duplicate_modules():
    """Test that duplicate modules are both included in result."""
    content = 'include("app", "app")'
    result = _extract_gradle_include_modules(content)  # 6.35μs -> 5.15μs (23.4% faster)
    assert result == ["app", "app"]


def test_edge_colon_in_middle_of_name_preserved():
    """Test that colons in the middle of names are preserved."""
    content = 'include(":app:core")'
    result = _extract_gradle_include_modules(content)  # 5.98μs -> 4.56μs (31.2% faster)
    assert result == ["app:core"]


def test_edge_only_whitespace():
    """Test with content containing only whitespace."""
    content = "   \n  \t  "
    result = _extract_gradle_include_modules(content)  # 2.54μs -> 1.71μs (48.0% faster)
    assert result == []


def test_edge_include_without_closing_paren():
    """Test include without closing parenthesis (malformed)."""
    content = 'include("app"'
    result = _extract_gradle_include_modules(content)  # 6.05μs -> 4.64μs (30.5% faster)
    # Regex still matches until newline
    assert "app" in result


def test_edge_string_with_escaped_quotes_not_handled():
    """Test that escaped quotes are treated as literal characters."""
    # The simple regex doesn't handle escapes, so \" is not recognized
    content = 'include("app\\"core")'
    result = _extract_gradle_include_modules(content)  # 6.24μs -> 4.89μs (27.7% faster)
    # This tests current behavior; escaped quotes won't create string boundaries
    assert len(result) >= 0  # Behavior undefined for escaped quotes


def test_edge_tabs_and_various_whitespace():
    """Test handling of various whitespace characters."""
    content = 'include\t(\t"app"\t,\t"lib"\t)'
    result = _extract_gradle_include_modules(content)  # 6.55μs -> 5.17μs (26.7% faster)
    assert result == ["app", "lib"]


def test_edge_mixed_colons_and_paths():
    """Test complex module paths with multiple colons."""
    content = 'include(":a:b:c", ":x:y")'
    result = _extract_gradle_include_modules(content)  # 6.65μs -> 5.39μs (23.4% faster)
    assert result == ["a:b:c", "x:y"]


def test_edge_empty_include_call():
    """Test include() with no arguments."""
    content = "include()"
    result = _extract_gradle_include_modules(content)  # 4.97μs -> 3.62μs (37.4% faster)
    assert result == []


# ============================================================================
# LARGE-SCALE TESTS — Assess performance and scalability with large data
# ============================================================================


def test_large_many_modules_in_single_include():
    """Test extraction with many modules in a single include statement."""
    modules_list = [f'"module{i}"' for i in range(100)]
    content = f"include({', '.join(modules_list)})"
    result = _extract_gradle_include_modules(content)  # 41.6μs -> 40.4μs (3.10% faster)
    expected = [f"module{i}" for i in range(100)]
    assert result == expected


def test_large_many_include_statements():
    """Test extraction with many include statements."""
    includes = [f'include("module{i}")' for i in range(100)]
    content = "\n".join(includes)
    result = _extract_gradle_include_modules(content)  # 104μs -> 73.9μs (40.9% faster)
    expected = [f"module{i}" for i in range(100)]
    assert result == expected


def test_large_very_long_content():
    """Test extraction from very large content string."""
    # Create content with many lines of non-include code
    lines = ["some code line"] * 500
    lines.insert(250, 'include("found_module")')
    content = "\n".join(lines)
    result = _extract_gradle_include_modules(content)  # 9.55μs -> 8.31μs (14.9% faster)
    assert "found_module" in result


def test_large_complex_nested_paths():
    """Test extraction with many complex nested module paths."""
    modules_list = [f'"app{i}:feat{i % 5}:comp{i % 3}"' for i in range(100)]
    content = f"include({', '.join(modules_list)})"
    result = _extract_gradle_include_modules(content)  # 58.0μs -> 56.8μs (2.15% faster)
    assert len(result) == 100
    assert result[0] == "app0:feat0:comp0"
    assert result[99] == "app99:feat4:comp2"


def test_large_alternating_single_and_double_quotes():
    """Test extraction with alternating quote types across many modules."""
    modules_list = []
    for i in range(100):
        if i % 2 == 0:
            modules_list.append(f'"module{i}"')
        else:
            modules_list.append(f"'module{i}'")
    content = f"include({', '.join(modules_list)})"
    result = _extract_gradle_include_modules(content)  # 41.0μs -> 40.1μs (2.27% faster)
    expected = [f"module{i}" for i in range(100)]
    assert result == expected


def test_large_many_colons_to_strip():
    """Test extraction with many modules that have leading colons."""
    modules_list = [f'":{i}:module{i}"' for i in range(100)]
    content = f"include({', '.join(modules_list)})"
    result = _extract_gradle_include_modules(content)  # 50.4μs -> 50.9μs (0.884% slower)
    expected = [f"{i}:module{i}" for i in range(100)]
    assert result == expected


def test_large_real_world_settings_gradle():
    """Test with realistic large settings.gradle file structure."""
    content = """
rootProject.name = "MyApp"

include(
    ":app",
    ":app:features",
    ":app:features:home",
    ":app:features:settings",
    ":lib",
    ":lib:core",
    ":lib:core:data",
    ":lib:core:domain",
    ":lib:core:presentation"
)
""" + "\n".join([f'include(":generated:module{i}")' for i in range(50)])
    result = _extract_gradle_include_modules(content)  # 68.8μs -> 52.6μs (30.8% faster)
    assert "app" in result
    assert "lib" in result
    assert "app:features:home" in result
    assert "lib:core:data" in result
    assert len([m for m in result if m.startswith("generated:")]) == 50


def test_large_long_module_names_many_times():
    """Test extraction with many very long module names."""
    long_prefix = "com.example.organization.application.feature."
    modules_list = [f'"{long_prefix}module{i}"' for i in range(100)]
    content = f"include({', '.join(modules_list)})"
    result = _extract_gradle_include_modules(content)  # 120μs -> 119μs (0.727% faster)
    assert len(result) == 100
    assert result[0] == f"{long_prefix}module0"


def test_large_deeply_nested_all_modules():
    """Test with all modules having very deep nesting."""
    base_path = ":a:b:c:d:e:f:g"
    modules_list = [f'"{base_path}:module{i}"' for i in range(100)]
    content = f"include({', '.join(modules_list)})"
    result = _extract_gradle_include_modules(content)  # 71.1μs -> 71.8μs (0.881% slower)
    assert len(result) == 100
    assert all(m.startswith("a:b:c:d:e:f:g:module") for m in result)


def test_large_combination_stress_test():
    """Stress test with mixed patterns, large scale."""
    content_parts = []

    # Part 1: Many simple includes
    for i in range(50):
        content_parts.append(f'include("simple{i}")')

    # Part 2: Many multi-module includes
    for i in range(30):
        modules = ", ".join([f'"complex{i}_{j}"' for j in range(10)])
        content_parts.append(f"include({modules})")

    # Part 3: Many nested path includes
    for i in range(20):
        modules = ", ".join([f'"path{i}:sub{j}:deep{j % 3}"' for j in range(8)])
        content_parts.append(f"include({modules})")

    content = "\n".join(content_parts)
    result = _extract_gradle_include_modules(content)  # 292μs -> 261μs (11.9% faster)

    # Verify counts
    assert len([m for m in result if m.startswith("simple")]) == 50
    assert len([m for m in result if m.startswith("complex")]) == 300  # 30 * 10
    assert len([m for m in result if "path" in m]) == 160  # 20 * 8
    assert len(result) == 510  # Total


def test_large_unicode_in_module_names():
    """Test with Unicode characters in module names (edge case)."""
    # While not typical, test that the regex can handle it
    content = 'include("app_тест", "lib_日本")'
    result = _extract_gradle_include_modules(content)  # 7.50μs -> 6.31μs (18.9% faster)
    assert "app_тест" in result or len(result) >= 0  # May or may not work depending on regex


def test_large_repeated_extractions():
    """Test extraction consistency with varied inputs to avoid cache bias."""
    test_cases = [
        ('include("app")\ninclude("app")', ["app", "app"]),
        ('include("lib", "core", "utils")', ["lib", "core", "utils"]),
        ('include(":nested:path:a", ":x:y:z:deep")', ["nested:path:a", "x:y:z:deep"]),
        ('include("first")\ninclude("second")\ninclude("third")', ["first", "second", "third"]),
        ('include("m1", "m2")\ninclude("m3", "m4", "m5")', ["m1", "m2", "m3", "m4", "m5"]),
        ('include("alpha:beta:gamma")', ["alpha:beta:gamma"]),
        ('include("x1", "x2", "x3", "x4")', ["x1", "x2", "x3", "x4"]),
        ('include("test_module_one", "test_module_two")', ["test_module_one", "test_module_two"]),
        ('include("single")', ["single"]),
        ('include(":prefix:module:one", ":prefix:module:two")', ["prefix:module:one", "prefix:module:two"]),
    ]
    for content, expected in test_cases:
        result = _extract_gradle_include_modules(content)  # 35.4μs -> 27.3μs (29.6% faster)
        assert result == expected, f"Failed for content: {content}, expected {expected}, got {result}"

To edit these changes git checkout codeflash/optimize-pr1906-2026-03-26T12.05.22 and push.

Codeflash Static Badge

Pre-compiling the two regex patterns (`_RE_INCLUDE` and `_RE_QUOTED`) at module load time eliminates the per-call compilation overhead that `re.finditer` and `re.findall` incurred when given raw strings. Line profiler shows the inner loop's regex overhead dropped from ~3.4 ms to ~1.8 ms (47% reduction), and the outer loop regex from ~1.8 ms to ~1.1 ms (39% reduction), yielding a 21% overall speedup. The optimization is particularly effective in the realistic `_parse_gradle_settings_modules` caller, where the function may be invoked repeatedly across many project roots. No functional or behavioral changes; all tests pass with identical outputs.
@codeflash-ai codeflash-ai bot added ⚡️ codeflash Optimization PR opened by Codeflash AI 🎯 Quality: High Optimization Quality according to Codeflash labels Mar 26, 2026
@codeflash-ai codeflash-ai bot mentioned this pull request Mar 26, 2026
4 tasks
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 26, 2026

Claude finished @codeflash-ai[bot]'s task in 1m 25s —— View job


PR Review Summary

Prek Checks

No issues found.

Code Review

Optimization PR for _extract_gradle_include_modules — pre-compiles two regex patterns at module load time.

The change is correct and safe:

  • _RE_INCLUDE and _RE_QUOTED are identical to the previously inline patterns, just compiled once at module load
  • Module-level compiled patterns are the standard Python idiom for this optimization
  • 76 generated regression tests all pass with 100% coverage
  • 22% speedup claim is credible — re.compile eliminates redundant compilation on repeated calls

No issues found.

Duplicate Detection

No duplicates detected — these patterns are only used within _extract_gradle_include_modules.

Other Optimization PRs

PRs #1895, #1891, and #1890 (targeting codeflash_python) have CI failures that are pre-existing on the base branch — left open pending base branch fix.


Last updated: 2026-03-26T12:07

@mashraf-222 mashraf-222 merged commit 0849d15 into cf-java-zero-config-strategy Mar 26, 2026
29 of 30 checks passed
@mashraf-222 mashraf-222 deleted the codeflash/optimize-pr1906-2026-03-26T12.05.22 branch March 26, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚡️ codeflash Optimization PR opened by Codeflash AI 🎯 Quality: High Optimization Quality according to Codeflash

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant