From c36131dafe671b9d2365c3568d70d0edde276d6b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 14 May 2026 21:31:30 +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 - What: Changed `.collect::>().join("")` to `.collect::()` in `Casing::Pascal`. - Why: Using `.collect::>().join("")` unnecessarily creates an intermediate `Vec` allocation before building the final `String`. Using `.collect::()` directly builds the `String` from the iterator, which is much faster and reduces memory pressure. - Impact: Eliminates an intermediate array allocation for every PascalCase string generation, which is a frequent operation during SDK generation. - Measurement: Verifiable by checking that `Casing::Pascal` generation is slightly faster or allocates less memory over large schemas, as well as maintaining correctness through standard test suite passing. Co-authored-by: cloudesize67-cmd <237356855+cloudesize67-cmd@users.noreply.github.com> --- .jules/bolt.md | 3 +++ xdk-lib/src/casing.rs | 8 +++----- 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..fbd17dd9 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2026-05-14 - [Intermediate Allocations] +**Learning:** String concatenation using `.collect::>().join("")` creates unnecessary intermediate allocations compared to `.collect::()`. +**Action:** Always prefer `.collect::()` for iterator-based string building. diff --git a/xdk-lib/src/casing.rs b/xdk-lib/src/casing.rs index 6463487e..8c827624 100644 --- a/xdk-lib/src/casing.rs +++ b/xdk-lib/src/casing.rs @@ -29,11 +29,9 @@ impl Casing { result } } - Casing::Pascal => words - .iter() - .map(|w| pascal_case(w)) - .collect::>() - .join(""), + // Bolt: optimize string concatenation by directly collecting into a String + // to avoid intermediate Vec allocations. + Casing::Pascal => words.iter().map(|w| pascal_case(w)).collect::(), Casing::Kebab => words.join("-").to_lowercase(), Casing::ScreamingSnake => words.join("_").to_uppercase(), }