From 26e5897ad8f75476a19eef89f032d4fbc144e7af Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 10 May 2026 21:19:46 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Optimized `xdk-build/src/python.rs` to use character-based splits and iterate without allocating intermediate `Vec` elements. - Optimized `xdk-lib/src/casing.rs` to use `.collect::()` instead of allocating an intermediate `Vec` to join components. Co-authored-by: cloudesize67-cmd <237356855+cloudesize67-cmd@users.noreply.github.com> --- .jules/bolt.md | 3 +++ xdk-build/src/python.rs | 17 +++++++---------- xdk-lib/src/casing.rs | 6 +----- 3 files changed, 11 insertions(+), 15 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..3d66a051 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-24 - [Avoid Unnecessary Vec Allocations for Iterator Output] +**Learning:** Using `.collect::>().join("")` allocates an unnecessary intermediate `Vec` when building strings from iterators. Using `.collect::()` performs the same logic without intermediate vector allocations. Also replacing `.split("\n").collect::>().into_iter()` with `.split('\n')` and similar for space separating eliminates multiple `Vec` allocations during string formatting. +**Action:** Always prefer `.collect::()` over `.collect::>().join("")` when concatenating string components in Rust. For string splitting, use direct iterator methods over intermediate collection. \ No newline at end of file diff --git a/xdk-build/src/python.rs b/xdk-build/src/python.rs index 1d15d6f0..cd7919d6 100644 --- a/xdk-build/src/python.rs +++ b/xdk-build/src/python.rs @@ -159,16 +159,13 @@ fn run_formatter(output_dir: &Path, venv_python_path: &Path, script_path: &Path) let stdout = String::from_utf8_lossy(&output.stdout); if !stdout.trim().is_empty() { println!(); - stdout - .split("\n") - .collect::>() - .into_iter() - .for_each(|line| { - let parts = line.split(" ").collect::>(); - if parts.len() == 2 { - log_info!("{} {}", parts[0], parts[1].magenta()); - } - }); + // Optimization: Use character splits and avoid allocating Vecs for lines and parts + for line in stdout.split('\n') { + let mut parts = line.split(' '); + if let (Some(part0), Some(part1), None) = (parts.next(), parts.next(), parts.next()) { + log_info!("{} {}", part0, part1.magenta()); + } + } println!(); } diff --git a/xdk-lib/src/casing.rs b/xdk-lib/src/casing.rs index 6463487e..7a6c9293 100644 --- a/xdk-lib/src/casing.rs +++ b/xdk-lib/src/casing.rs @@ -29,11 +29,7 @@ impl Casing { result } } - Casing::Pascal => words - .iter() - .map(|w| pascal_case(w)) - .collect::>() - .join(""), + Casing::Pascal => words.iter().map(|w| pascal_case(w)).collect::(), // Optimization: Use collect::() directly instead of collecting to Vec and joining Casing::Kebab => words.join("-").to_lowercase(), Casing::ScreamingSnake => words.join("_").to_uppercase(), }