From 652033d6eebd7f1d78f37ebd91952d3d3cedd164 Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Fri, 13 Mar 2026 01:55:24 +0000 Subject: [PATCH] Optimize _get_git_remote_for_setup The optimization added `@cache` to `_get_theme()`, which instantiates a `CodeflashTheme` object by importing `init_config` and calling its constructor. Line profiler shows the original version spent ~12.3 ms per call (6.5 ms on import, 5.8 ms on instantiation). Since `_get_git_remote_for_setup` calls `_get_theme()` inside `inquirer.prompt` every time multiple remotes exist, repeated calls in a session (or across test cases) re-executed this work. Caching the theme object eliminated redundant imports and constructor calls, reducing the per-call overhead in `_get_git_remote_for_setup` from ~12.8 ms to ~7.5 ms (visible in the `inquirer.prompt` line dropping from 12.8 ms to 7.5 ms). The 18% runtime improvement comes from amortizing theme creation across all invocations, with the largest gains in tests simulating multiple-remote scenarios where the function is called repeatedly. --- codeflash/cli_cmds/init_java.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codeflash/cli_cmds/init_java.py b/codeflash/cli_cmds/init_java.py index 161c53d21..6d972664c 100644 --- a/codeflash/cli_cmds/init_java.py +++ b/codeflash/cli_cmds/init_java.py @@ -7,6 +7,7 @@ import xml.etree.ElementTree as ET from dataclasses import dataclass from enum import Enum, auto +from functools import cache from pathlib import Path from typing import Any, Union @@ -55,6 +56,7 @@ class JavaSetupInfo: benchmarks_root: Union[str, None] = None +@cache def _get_theme(): """Get the CodeflashTheme - imported lazily to avoid circular imports.""" from codeflash.cli_cmds.init_config import CodeflashTheme