From fd54508354af4b1f7097a02eb8bd151f2dd4916a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 31 May 2026 21:11:27 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20Optimize=20stdout=20parsing=20by=20removing=20intermediate?= =?UTF-8?q?=20allocations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💡 What: Replaced string-based `.split("\n")` and `.split(" ")` with character-based `.split('\n')` and `.split(' ')`. Eliminated the intermediate `Vec` allocations (`.collect::>().into_iter()`). Used pattern matching with multiple `.next()` calls to safely extract the parts instead of allocating a `Vec` to check its length. 🎯 Why: The original code collected the entire command stdout into a dynamically allocated vector, then iterated over it immediately, and for each line, allocated another vector just to extract the first two elements. This creates significant unnecessary heap allocations which can slow down execution, especially for verbose command output. 📊 Impact: Removes 1+N heap allocations (where N is the number of lines in the command's stdout), reducing memory pressure and marginally improving execution speed. 🔬 Measurement: Run `make check` and `make test-generator` to verify no regressions in functionality and that formatting is maintained. Co-authored-by: cloudesize67-cmd <237356855+cloudesize67-cmd@users.noreply.github.com> --- xdk-build/src/python.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/xdk-build/src/python.rs b/xdk-build/src/python.rs index 1d15d6f0..d242c693 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-based split and pattern matching to avoid intermediate Vec allocations + stdout.split('\n').for_each(|line| { + let mut parts = line.split(' '); + if let (Some(part0), Some(part1), None) = (parts.next(), parts.next(), parts.next()) { + log_info!("{} {}", part0, part1.magenta()); + } + }); println!(); }