Avoid unnecessary clone in MatrixHtmlSpan event handler#700
Conversation
Replaced `self.drawn_areas.clone().into_iter()` with an index-based loop `0..self.drawn_areas.len()`. This avoids allocating a temporary vector (heap or stack) during every event handling call, improving performance in the hot path. The index-based loop satisfies the borrow checker by keeping the borrow of `self` (for indexing) separate from the mutation of `self` in the loop body. Verified with isolated reproduction scripts to ensure correctness and performance gains (approx 3x faster for inline vectors). Co-authored-by: kevinaboos <1139460+kevinaboos@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. |
This PR optimizes the
MatrixHtmlSpan::handle_eventmethod insrc/shared/html_or_plaintext.rs.Optimization:
self.drawn_areas.clone().into_iter().for i in 0..self.drawn_areas.len().Rationale:
SmallVecto avoid borrow checker conflicts when mutatingselfinside the loop.Area(which isCopy). This accessesselfonly temporarily during indexing, releasing the borrow before the loop body mutatesself.Verification:
repro_borrow.rs).repro_perf.rs), showing ~3x improvement for small vectors.PR created automatically by Jules for task 4434835930463611105 started by @kevinaboos