Skip to content

Commit c65151a

Browse files
ctruedenclaude
andcommitted
Make jar tool acquisition lazy
Performance improvement for warm cache scenarios: **Problem:** The baseline jar tool (Java 11 via cjdk) was being acquired on every run, even when all JARs hit the metadata cache and the tool was never needed. **Solution:** Implement lazy evaluation using a closure-based approach. The jar tool is now only acquired when there's a cache miss and we need to classify a non-modular JAR. **Performance gain:** Skips expensive Java locator call when cache is warm (100% cache hit rate). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent 2980253 commit c65151a

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/jgo/env/builder.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,19 @@ def _build_environment(
711711
if version:
712712
min_java_version = max(min_java_version or 0, version)
713713

714-
# Get baseline JDK for module classification
715-
# This uses a consistent Java 11 via cjdk, ensuring deterministic builds
716-
# regardless of what Java version is on the system PATH
717-
jar_tool = get_baseline_jar_tool()
714+
# Lazy-initialize baseline jar tool only when needed
715+
# Sentinel value to detect if we've tried to get it yet
716+
jar_tool_state = {"tool": None, "initialized": False}
717+
718+
def get_jar_tool_lazy():
719+
"""Get baseline jar tool lazily (only when actually needed)."""
720+
if not jar_tool_state["initialized"]:
721+
# Get baseline JDK for module classification
722+
# This uses a consistent Java 11 via cjdk, ensuring deterministic builds
723+
# regardless of what Java version is on the system PATH
724+
jar_tool_state["tool"] = get_baseline_jar_tool()
725+
jar_tool_state["initialized"] = True
726+
return jar_tool_state["tool"]
718727

719728
# Helper function to classify and link a JAR artifact
720729
def process_artifact(artifact, source_path):
@@ -728,6 +737,9 @@ def process_artifact(artifact, source_path):
728737
# Use fast module detection (no subprocess)
729738
module_info = detect_module_info(source_path)
730739

740+
# Get jar tool lazily only when we need it
741+
jar_tool = get_jar_tool_lazy()
742+
731743
if jar_tool:
732744
# Baseline jar tool available - use precise classification
733745
if module_info.is_modular:
@@ -760,11 +772,11 @@ def process_artifact(artifact, source_path):
760772
)
761773

762774
# Determine target directory based on jar_type
763-
if jar_tool and jar_type is not None:
775+
if jar_type is not None:
764776
# Types 1/2/3 are modularizable, type 4 is not
765777
target_dir = modules_dir if jar_type in (1, 2, 3) else jars_dir
766778
else:
767-
# No jar tool or no classification - use module_info
779+
# No classification - use module_info
768780
target_dir = modules_dir if module_info.is_modular else jars_dir
769781

770782
dest_path = target_dir / artifact.filename

0 commit comments

Comments
 (0)