⚡ Bolt: [performance improvement] Avoid intermediate Vector allocations during casing conversions - #84
Conversation
…ns during casing conversions
This commit optimizes two functions in `xdk-lib/src/casing.rs`:
- In `convert_words`, it replaces `.collect::<Vec<_>>().join("")` with `.collect::<String>()` when concatenating strings in `Casing::Pascal` to avoid unnecessary intermediate Vector allocations.
- In `camel_case`, it updates `.to_lowercase().collect::<String>()` to `.to_lowercase().to_string()` for slightly better performance and readability, relying on the built-in `Display` implementation.
Co-authored-by: cloudesize67-cmd <237356855+cloudesize67-cmd@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: Optimized formatting functions in
xdk-lib/src/casing.rsby preventing unnecessary intermediate Vector allocations during string conversions. Replaced.collect::<Vec<_>>().join("")with.collect::<String>(), and.to_lowercase().collect::<String>()with.to_lowercase().to_string().🎯 Why: The original string concatenation first allocated a
Vecarray on the heap, populated it, then performed another iteration and allocation during the.joincall. This wastes cycles. By replacing it with.collect::<String>()(which is supported sinceStringimplementsFromIterator<&str>/FromIterator<String>), we allocate a single String directly. In addition, using.to_string()avoids iterator collection overhead and is much cleaner.📊 Impact: Reduces intermediate heap memory allocations during SDK code generation when casing components (a very common operation during compilation). It prevents 1
Vecallocation per string converted to Pascal case.🔬 Measurement: Verifiable by the complete successful execution of
make test-generator, which ensures functional equivalence, and code health tests viamake check.PR created automatically by Jules for task 2263035892258016309 started by @cloudesize67-cmd