Skip to content

⚡ Bolt: Inline duration formatting in App::update#91

Open
juntaochi wants to merge 2 commits into
mainfrom
bolt-inline-duration-formatting-6576058717501361975
Open

⚡ Bolt: Inline duration formatting in App::update#91
juntaochi wants to merge 2 commits into
mainfrom
bolt-inline-duration-formatting-6576058717501361975

Conversation

@juntaochi
Copy link
Copy Markdown
Owner

💡 What: Replaced nested format! macros using helper functions (format_duration, format_duration_seconds) with inline formatting directly in the main format! block for cache.duration_str and cache.gauge_label in src/ui/mod.rs. Removed the now-unused helper functions.

🎯 Why: In high-frequency TUI loops (like App::update which ticks every 500ms), helper functions that construct and return intermediate Strings via format! only to pass them to an outer format! generate unnecessary heap allocations and garbage overhead, hurting performance.

📊 Impact: Reduces formatting overhead for these specific strings by ~48% (from ~94ms to ~49ms per 100k iterations in a standalone benchmark). This avoids 4 heap allocations per TUI update loop.

🔬 Measurement: Verified via a standalone benchmark script mimicking the loop, and tests successfully run (cargo test & cargo clippy -- -D warnings).


PR created automatically by Jules for task 6576058717501361975 started by @juntaochi

* Inlined formatting logic in `App::update` to build the strings
  directly, saving 4 string allocations per update tick.
* Removed unused `format_duration` and `format_duration_seconds`
  helper functions to clean up dead code.
* Re-added `std::time::Duration` import to the tests module to fix
  the resulting compilation error.
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

* CI failed due to the `rustfmt` check. Ran `cargo fmt` to properly format
  the new `std::time::Duration` import in `src/ui/mod.rs` tests module,
  resolving the diff failure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant