Skip to content

Commit 3ed5c2b

Browse files
tusharmathlaststylebender14
authored andcommitted
perf(ui): make forge info 14x faster (#2123)
1 parent 501066d commit 3ed5c2b

2 files changed

Lines changed: 96 additions & 3 deletions

File tree

crates/forge_main/src/ui.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ impl<A: API + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
270270
}
271271

272272
async fn run_inner(&mut self) -> Result<()> {
273-
if let Some(mcp) = self.cli.subcommands.clone() {
274-
return self.handle_subcommands(mcp).await;
273+
if let Some(cmd) = self.cli.subcommands.clone() {
274+
return self.handle_subcommands(cmd).await;
275275
}
276276

277277
// Display the banner in dimmed colors since we're in interactive mode
@@ -2291,7 +2291,6 @@ impl<A: API + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
22912291
let workflow = self.api.read_workflow(self.cli.workflow.as_deref()).await?;
22922292

22932293
let _ = self.handle_migrate_credentials().await;
2294-
self.install_vscode_extension();
22952294

22962295
// Ensure we have a model selected before proceeding with initialization
22972296
let active_agent = self.api.get_active_agent().await;
@@ -2361,6 +2360,8 @@ impl<A: API + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
23612360
async fn on_message(&mut self, content: Option<String>) -> Result<()> {
23622361
let conversation_id = self.init_conversation().await?;
23632362

2363+
self.install_vscode_extension();
2364+
23642365
// Track if content was provided to decide whether to use piped input as
23652366
// additional context
23662367
let has_content = content.is_some();
@@ -3107,6 +3108,9 @@ impl<A: API + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
31073108

31083109
/// Silently install VS Code extension if in VS Code and extension not
31093110
/// installed.
3111+
/// NOTE: This is a non-cancellable and a slow task. We should only run this
3112+
/// if the user has provided a prompt because that is guaranteed to run for
3113+
/// at least a few seconds.
31103114
fn install_vscode_extension(&self) {
31113115
tokio::task::spawn_blocking(|| {
31123116
if crate::vscode::should_install_extension() {
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env bash
2+
3+
# Performance test script for forge info command
4+
# Runs the command 10 times and collects timing statistics
5+
6+
set -euo pipefail
7+
8+
# Colors and styling
9+
BOLD='\033[1m'
10+
DIM='\033[2m'
11+
RESET='\033[0m'
12+
GREEN='\033[32m'
13+
YELLOW='\033[33m'
14+
CYAN='\033[36m'
15+
GRAY='\033[90m'
16+
17+
# Configuration
18+
COMMAND="target/debug/forge info"
19+
ITERATIONS=10
20+
TIMES=()
21+
22+
# Header
23+
echo ""
24+
echo -e "🚀 ${BOLD}Performance Test${RESET} ${DIM}${RESET} ${CYAN}forge info${RESET}"
25+
echo ""
26+
27+
# Build step
28+
echo -e "${GRAY}📦 Building...${RESET}"
29+
cargo build 2>&1 | grep -E "Compiling|Finished" | tail -1
30+
echo ""
31+
32+
# Show sample output
33+
echo -e "${GRAY}📋 Sample output:${RESET}"
34+
echo ""
35+
$COMMAND
36+
echo ""
37+
38+
# Run performance tests
39+
echo -e "${GRAY}⏱️ Running ${YELLOW}$ITERATIONS${GRAY} iterations...${RESET}"
40+
echo ""
41+
42+
for i in $(seq 1 $ITERATIONS); do
43+
# Measure execution time
44+
START=$(date +%s%N)
45+
$COMMAND > /dev/null 2>&1
46+
END=$(date +%s%N)
47+
48+
# Calculate duration in milliseconds
49+
DURATION=$(( (END - START) / 1000000 ))
50+
TIMES+=($DURATION)
51+
52+
# Color code based on performance
53+
if [ $DURATION -lt 50 ]; then
54+
COLOR=$GREEN
55+
elif [ $DURATION -lt 100 ]; then
56+
COLOR=$YELLOW
57+
else
58+
COLOR=$GRAY
59+
fi
60+
61+
printf " ${DIM}%2d${RESET} ${COLOR}%5d${RESET} ${DIM}ms${RESET}\n" $i $DURATION
62+
done
63+
64+
echo ""
65+
66+
# Calculate statistics
67+
TOTAL=0
68+
MIN=${TIMES[0]}
69+
MAX=${TIMES[0]}
70+
71+
for time in "${TIMES[@]}"; do
72+
TOTAL=$((TOTAL + time))
73+
if [ $time -lt $MIN ]; then
74+
MIN=$time
75+
fi
76+
if [ $time -gt $MAX ]; then
77+
MAX=$time
78+
fi
79+
done
80+
81+
AVG=$((TOTAL / ITERATIONS))
82+
83+
# Results summary
84+
echo -e "📊 ${BOLD}Summary${RESET}"
85+
echo ""
86+
printf " ${DIM}avg${RESET} ${CYAN}%5d${RESET} ${DIM}ms${RESET}\n" $AVG
87+
printf " ${DIM}min${RESET} ${GREEN}%5d${RESET} ${DIM}ms${RESET}\n" $MIN
88+
printf " ${DIM}max${RESET} ${YELLOW}%5d${RESET} ${DIM}ms${RESET}\n" $MAX
89+
echo ""

0 commit comments

Comments
 (0)