⚡ Optimize font handle cloning in update_circle_layout loop#6
⚡ Optimize font handle cloning in update_circle_layout loop#6dynamikdev wants to merge 1 commit intomasterfrom
Conversation
…tion outside the loop. This commit improves the performance of the `update_circle_layout` system in Bevy: 1. Moves the `typography.space_grotesk.clone()` call outside the `for` loop to avoid redundant atomic operations. 2. Calculates the final `font_size` once outside the loop. 3. Adds checks to only update `text_font.font` and `text_font.font_size` if they have actually changed, preventing unnecessary component mutations and triggering of Bevy's change detection. Co-authored-by: dynamikdev <717692+dynamikdev@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. |
The optimization in
src/ui/systems.rsaddresses the issue of redundant font handle cloning and unnecessary component updates in theupdate_circle_layoutsystem, which runs every frame.What: Moved font handle cloning and size calculation outside the main loop, and added conditional checks before updating the$N$ (where $N$ is the number of target entities, in this case 8) to 1 per frame for the font handle, and component mutations were eliminated for all cases where the layout remains static.
TextFontcomponent.Why: Cloning a Bevy
Handle(likeHandle<Font>) involves atomic reference counting, which is costly when repeated inside a loop that runs every frame. Additionally, updating a component's fields unconditionally triggers Bevy's change detection system, potentially causing unnecessary downstream work (like re-layout or re-rendering).Measured Improvement: Due to the inability to download dependencies (
bevy,bevy_ui_widgets) in this environment, a direct benchmark was not possible. However, this is a well-established optimization in Bevy for systems that update every frame. The number of atomic operations was reduced fromPR created automatically by Jules for task 11230702228547829404 started by @dynamikdev