Skip to content

Commit 6ffff93

Browse files
authored
Merge pull request #1827 from codeflash-ai/codeflash/optimize-pr1199-2026-03-13T01.44.29
⚡️ Speed up function `_prompt_custom_directory` by 363% in PR #1199 (`omni-java`)
2 parents 6da33f8 + 10a6ecb commit 6ffff93

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

codeflash/cli_cmds/init_java.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import xml.etree.ElementTree as ET
88
from dataclasses import dataclass
99
from enum import Enum, auto
10+
from functools import lru_cache
1011
from pathlib import Path
1112
from typing import Any, Union
1213

@@ -55,6 +56,7 @@ class JavaSetupInfo:
5556
benchmarks_root: Union[str, None] = None
5657

5758

59+
@lru_cache(maxsize=1)
5860
def _get_theme():
5961
"""Get the CodeflashTheme - imported lazily to avoid circular imports."""
6062
from codeflash.cli_cmds.init_config import CodeflashTheme
@@ -366,17 +368,15 @@ def _prompt_directory_override(dir_type: str, detected: str, curdir: Path) -> st
366368

367369
def _prompt_custom_directory(dir_type: str) -> str:
368370
"""Prompt for a custom directory path."""
371+
# Reuse the question object to avoid reconstructing it on every loop iteration.
372+
custom_question = inquirer.Path(
373+
"custom_path",
374+
message=f"Enter the path to your {dir_type} directory",
375+
path_type=inquirer.Path.DIRECTORY,
376+
exists=True,
377+
)
369378
while True:
370-
custom_questions = [
371-
inquirer.Path(
372-
"custom_path",
373-
message=f"Enter the path to your {dir_type} directory",
374-
path_type=inquirer.Path.DIRECTORY,
375-
exists=True,
376-
)
377-
]
378-
379-
custom_answers = inquirer.prompt(custom_questions, theme=_get_theme())
379+
custom_answers = inquirer.prompt([custom_question], theme=_get_theme())
380380
if not custom_answers:
381381
apologize_and_exit()
382382

0 commit comments

Comments
 (0)