Skip to content
Merged
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
Expand Up @@ -35,3 +35,6 @@
## 2024-05-24 - Canvas Property Extraction Optimization
**Learning:** Extracting properties from the `RuntimeValue` DSL property lists in `canvas.rs` was inefficient because the code called `.iter().find()` multiple times for each property in `logo`, `rings`, `emblem`, `letter`, `core`, and `circuits` definitions.
**Action:** Replace multiple `.find()` calls with a single-pass `for p in &dsl.properties` loop and `match` on the property names, mutating local fallback variables.
## 2024-11-20 - Avoid `format!` inside loops for hex string encoding
**Learning:** Using `.iter().map(|b| format!("{:02x}", b)).collect::<String>()` to encode a byte array to a hex string incurs a heavy performance penalty because it allocates a new temporary `String` for every single byte processed before concatenating them. The `hex::encode()` function from the `hex` crate performs this conversion directly into a single pre-allocated `String` with zero intermediate allocations.
**Action:** Always prefer `hex::encode(bytes)` over iterative `format!` mapping when performing hexadecimal encoding of byte arrays or slices to eliminate intermediate string allocations and significantly boost performance.
6 changes: 2 additions & 4 deletions stdlib/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ impl StdlibRegistry {
combined.extend_from_slice(&ciphertext);

// Hex encode ciphertext
let hex_ciphertext = combined
.iter()
.map(|b| format!("{:02x}", b))
.collect::<String>();
// ⚡ Bolt Performance Optimization: Replaced iterative format! with hex::encode for single-allocation hex string conversion.
let hex_ciphertext = hex::encode(combined);
Ok(RuntimeValue::Str(hex_ciphertext))
},
}),
Expand Down
6 changes: 4 additions & 2 deletions stdlib/src/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ impl StdlibRegistry {
use rand::Rng;
let bytes: Vec<u8> =
rand::thread_rng().gen::<[u8; 32]>()[..len.min(32)].to_vec();
let hex: String = bytes.iter().map(|b| format!("{:02x}", b)).collect();
// ⚡ Bolt Performance Optimization: Replaced iterative format! with hex::encode for single-allocation hex string conversion.
let hex = hex::encode(bytes);
Ok(RuntimeValue::Str(hex))
},
}),
Expand Down Expand Up @@ -48,7 +49,8 @@ impl StdlibRegistry {
let input = args[0].to_string();
use sha2::Digest;
let digest = sha2::Sha256::digest(input.as_bytes());
let hex: String = digest.iter().map(|b| format!("{:02x}", b)).collect();
// ⚡ Bolt Performance Optimization: Replaced iterative format! with hex::encode for single-allocation hex string conversion.
let hex = hex::encode(digest);
Ok(RuntimeValue::Str(hex))
},
}),
Expand Down
3 changes: 0 additions & 3 deletions test_perf.rs

This file was deleted.

Loading