Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-05-24 - Iterator Splitting Performance and Scratch Artifacts
**Learning:** In Rust, chained intermediate `Vec` allocations (`.collect::<Vec<_>>().into_iter()`) for operations like string splitting can be up to 2-3x slower than direct iteration. Replacing string splits with character splits (`.split('\n')`) provides an additional marginal boost. Additionally, using standalone scratch files (e.g. `test_perf.rs`) to verify performance claims locally is helpful due to network environment constraints, but the compiled binaries and scripts *must* be removed to avoid polluting the workspace repository prior to PR submission.
**Action:** Always prefer direct iteration over intermediate `Vec` collections. Always clean up local scratch files after validating hypotheses.
19 changes: 9 additions & 10 deletions xdk-build/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,15 @@ 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::<Vec<&str>>()
.into_iter()
.for_each(|line| {
let parts = line.split(" ").collect::<Vec<&str>>();
if parts.len() == 2 {
log_info!("{} {}", parts[0], parts[1].magenta());
}
});
// ⚡ Bolt: Eliminate intermediate Vec allocations by using iterators directly
// and using character-based splitting instead of string-based splitting.
stdout.split('\n').for_each(|line| {
let mut parts = line.split(' ');
// Ensure exactly two parts
if let (Some(part0), Some(part1), None) = (parts.next(), parts.next(), parts.next()) {
log_info!("{} {}", part0, part1.magenta());
}
});
println!();
}

Expand Down
Loading