⚡ Bolt: Use Cached Metadata to Avoid UI Rendering Allocations - #148
⚡ Bolt: Use Cached Metadata to Avoid UI Rendering Allocations#148juntaochi wants to merge 1 commit into
Conversation
Eliminates per-frame allocations for uppercase track metadata and gauge progress strings by leveraging the existing `metadata_cache` populated in the main `App::update` loop. Uses `Cow` to preserve lifetimes and gracefully fall back when the cache is absent.
|
👋 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: Modified
draw_metadataanddraw_progressinsrc/ui/mod.rsto consume strings (Cow<'_, str>) directly from the application'smetadata_cache(populated every ~500ms inApp::update), instead of dynamically allocating strings liketrack.name.to_uppercase()andformat!("{}/{}", ...)on every TUI frame.🎯 Why: TUI applications re-render extremely frequently (typically at 60fps or when animated). Doing repeated heap string allocations (
.to_uppercase()andformat!) inside the hotdrawpath causes unnecessary memory churn and processing overhead. The string data only needs recalculation when the track identity or playback position actually changes, which is already handled efficiently in the background update loop.📊 Impact: Significantly reduces heap allocations per frame by avoiding redundant formatting and casing logic. Ensures smoother animations (like text scrolling and throbbers) by removing garbage collection pressure.
🔬 Measurement: Verification passes
cargo clippy -- -D warningsandcargo test. Rendering tests continue to function seamlessly as the implementation gracefully falls back to dynamic allocations (Cow::Owned) if thecacheis omitted (e.g. in test mock environments).PR created automatically by Jules for task 1017169362803392720 started by @juntaochi