From 6ef780704cb659e09bf60ced66edfde0dbcdb649 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 9 May 2026 21:36:43 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20Avoid=20intermediate=20Vector=20allocations=20in=20xdk-build?= =?UTF-8?q?=20and=20xdk-lib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replaced string `.split("\n")` with character `.split('\n')` in `xdk-build/src/python.rs`. - Removed intermediate `.collect::>().into_iter()` on string split in `xdk-build/src/python.rs`. - Replaced `.collect::>().join("")` with `.collect::()` for String concatenation in `xdk-lib/src/casing.rs`. Co-authored-by: cloudesize67-cmd <237356855+cloudesize67-cmd@users.noreply.github.com> --- .jules/bolt.md | 3 +++ xdk-build/src/python.rs | 16 ++++++---------- xdk-lib/src/casing.rs | 6 +----- 3 files changed, 10 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..dc40f3f4 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-06-25 - [Rust Iterator Allocations] +**Learning:** In Rust, avoid intermediate allocations by iterating directly over iterator sources (like `.split()`) rather than calling `.collect::>().into_iter()`. Also, use character-based splits (e.g., `.split('\n')`) instead of string-based splits (e.g., `.split("\n")`) for single characters. Furthermore, when transforming and aggregating collections of strings, use `.collect::()` instead of `.collect::>().join("")` for string concatenation to prevent intermediate vector allocations. +**Action:** When working with iterators and strings in Rust, check for intermediate allocations that can be avoided by directly using `collect::()` or dropping `collect::>().into_iter()` from iterator chains. Use `char` arguments for single-character string functions to enhance performance. diff --git a/xdk-build/src/python.rs b/xdk-build/src/python.rs index 1d15d6f0..c90da4f9 100644 --- a/xdk-build/src/python.rs +++ b/xdk-build/src/python.rs @@ -159,16 +159,12 @@ 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()); - } - }); + stdout.split('\n').for_each(|line| { + let parts = line.split(' ').collect::>(); + if parts.len() == 2 { + log_info!("{} {}", parts[0], parts[1].magenta()); + } + }); println!(); } diff --git a/xdk-lib/src/casing.rs b/xdk-lib/src/casing.rs index 6463487e..0ee4c0d2 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::(), Casing::Kebab => words.join("-").to_lowercase(), Casing::ScreamingSnake => words.join("_").to_uppercase(), }