Skip to content

Commit f3777e0

Browse files
Merge pull request #375 from Tcode-Motion/bolt-report-optimizations-1455940033649940502
⚡ Bolt: Replace push_str(&format!(...)) with write!/writeln! in report generation
2 parents 49363c4 + 7e3977f commit f3777e0

2 files changed

Lines changed: 37 additions & 26 deletions

File tree

‎.jules/bolt.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@
7474
## 2026-09-28 - String Path Borrowing in std.fs Module
7575
**Learning:** Extracting string arguments via `try_into_string()` in standard library callbacks causes unnecessary string cloning and heap allocations even when arguments are already `RuntimeValue::Str`.
7676
**Action:** Borrow `&str` directly from `RuntimeValue::Str` using pattern matching rather than calling `try_into_string()` when passing string path arguments to file I/O operations.
77+
## 2026-11-05 - String Concatenation Optimization in Report Command\n**Learning:** Using `report.push_str(&format!(...))` inside multiple lines to build an output report string unnecessarily allocates temporary `String` objects for each formatted piece. This puts pressure on the heap and creates memory fragmentation.\n**Action:** Utilize the `std::fmt::Write` trait directly onto the mutable `String` buffer with `writeln!` or `write!` to completely bypass intermediate heap allocations when constructing large report strings.

‎cli/src/commands/report.rs‎

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use crate::commands::app::android::resolve_android_home;
77
use crate::exit_code::ExitCode;
88
use colored::Colorize;
9+
use std::fmt::Write;
910
use std::fs;
1011
use std::path::PathBuf;
1112
use std::process::Command;
@@ -33,30 +34,33 @@ pub fn execute() -> ExitCode {
3334
let current_dir = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."));
3435
let mut report = String::new();
3536

36-
report.push_str("# TechScript 2.0 Diagnostic & Environment Report\n\n");
37-
report.push_str(&format!("- **Timestamp**: {}\n", chrono_timestamp()));
38-
report.push_str(&format!(
39-
"- **TechScript Compiler Version**: {}\n",
37+
let _ = writeln!(report, "# TechScript 2.0 Diagnostic & Environment Report\n");
38+
let _ = writeln!(report, "- **Timestamp**: {}", chrono_timestamp());
39+
let _ = writeln!(
40+
report,
41+
"- **TechScript Compiler Version**: {}",
4042
techscript_common::TECHSCRIPT_VERSION
41-
));
42-
report.push_str(&format!(
43-
"- **Working Directory**: `{}`\n",
43+
);
44+
let _ = writeln!(
45+
report,
46+
"- **Working Directory**: `{}`",
4447
current_dir.display()
45-
));
48+
);
4649

4750
println!("Collecting environment metadata...");
4851

4952
// Host OS & CPU
50-
report.push_str("\n## Host Environment\n");
51-
report.push_str(&format!("- **OS**: {}\n", std::env::consts::OS));
52-
report.push_str(&format!("- **Architecture**: {}\n", std::env::consts::ARCH));
53+
let _ = writeln!(report, "\n## Host Environment");
54+
let _ = writeln!(report, "- **OS**: {}", std::env::consts::OS);
55+
let _ = writeln!(report, "- **Architecture**: {}", std::env::consts::ARCH);
5356

5457
// Rust
5558
if let Ok(out) = Command::new("rustc").arg("--version").output() {
56-
report.push_str(&format!(
57-
"- **Rustc**: {}\n",
59+
let _ = writeln!(
60+
report,
61+
"- **Rustc**: {}",
5862
String::from_utf8_lossy(&out.stdout).trim()
59-
));
63+
);
6064
}
6165

6266
// Java
@@ -66,7 +70,7 @@ pub fn execute() -> ExitCode {
6670
String::from_utf8_lossy(&out.stdout),
6771
String::from_utf8_lossy(&out.stderr)
6872
);
69-
report.push_str(&format!("- **JDK (javac)**: {}\n", ver.trim()));
73+
let _ = writeln!(report, "- **JDK (javac)**: {}", ver.trim());
7074
}
7175

7276
// Gradle
@@ -76,23 +80,28 @@ pub fn execute() -> ExitCode {
7680
.lines()
7781
.find(|l| l.contains("Gradle "))
7882
.unwrap_or("Gradle installed");
79-
report.push_str(&format!("- **Gradle**: {}\n", first.trim()));
83+
let _ = writeln!(report, "- **Gradle**: {}", first.trim());
8084
}
8185

8286
// Android SDK
83-
report.push_str("\n## Android Toolchain\n");
87+
let _ = writeln!(report, "\n## Android Toolchain");
8488
match resolve_android_home() {
85-
Ok(sdk) => report.push_str(&format!("- **ANDROID_HOME**: `{}`\n", sdk)),
86-
Err(e) => report.push_str(&format!("- **ANDROID_HOME**: Missing ({})\n", e)),
89+
Ok(sdk) => {
90+
let _ = writeln!(report, "- **ANDROID_HOME**: `{}`", sdk);
91+
}
92+
Err(e) => {
93+
let _ = writeln!(report, "- **ANDROID_HOME**: Missing ({})", e);
94+
}
8795
}
8896

8997
// ADB
9098
if let Ok(out) = Command::new("adb").arg("version").output() {
9199
let line = String::from_utf8_lossy(&out.stdout);
92-
report.push_str(&format!(
93-
"- **ADB Version**: {}\n",
100+
let _ = writeln!(
101+
report,
102+
"- **ADB Version**: {}",
94103
line.lines().next().unwrap_or("").trim()
95-
));
104+
);
96105
}
97106

98107
// Devices
@@ -102,13 +111,14 @@ pub fn execute() -> ExitCode {
102111
for line in text.lines() {
103112
if line.ends_with("device") {
104113
count += 1;
105-
report.push_str(&format!(
106-
" - Device: `{}`\n",
114+
let _ = writeln!(
115+
report,
116+
" - Device: `{}`",
107117
line.split_whitespace().next().unwrap_or("")
108-
));
118+
);
109119
}
110120
}
111-
report.push_str(&format!("- **Attached Devices**: {}\n", count));
121+
let _ = writeln!(report, "- **Attached Devices**: {}", count);
112122
}
113123

114124
// Save report to reports/report.md

0 commit comments

Comments
 (0)