⚡ Bolt: [performance improvement] avoid intermediate String allocations for track duration formatting - #143
Conversation
Replaced `format_duration` and `format_duration_seconds` functions (which allocated intermediate Strings) with `DisplayDuration` and `DisplayDurationSeconds` wrapper structs that implement `std::fmt::Display`. This avoids intermediate heap allocations during the high-frequency UI rendering loop.
|
👋 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:
Replaced the
format_durationandformat_duration_secondshelper functions with newtype wrappers (DisplayDurationandDisplayDurationSeconds) that implementstd::fmt::Display.🎯 Why:
The original functions allocated a
String(e.g.,"03:45"or"225s") which was then immediately passed into anotherformat!macro during the UI loop. This caused unnecessary intermediate heap allocations on every render tick for the progress bar and metadata sections.📊 Impact:
Eliminates 8 redundant
Stringheap allocations per tick insrc/ui/mod.rs(draw_progressand metadata caching). By utilizingstd::fmt::Display, formatting is written directly to the outer buffer, providing a zero-cost abstraction without sacrificing readability.🔬 Measurement:
Run
cargo clippy -- -D warningsandcargo testto verify behavior remains completely identical while avoiding allocations. Benchmark of theDisplaypattern via independent rustc test verifies identical output format.PR created automatically by Jules for task 2197866325734240190 started by @juntaochi