⚡ Optimize bounded LRU cache lookup for TextPainter line box - #18
Conversation
Avoid unnecessary LinkedHashMap removal and re-insertion on cache hits when the requested key is already the most recently used (MRU) key. Co-authored-by: esenmx <43244505+esenmx@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. |
|
Thanks for the patch — LRU ordering is indeed preserved (the full suite passes on this branch), but the performance premise holds only for same-key hits and inverts for every other hit. |
Understood. Thank you for the detailed analysis on Dart's LinkedHashMap mechanics, key comparison overhead, and micro-benchmark findings across hit patterns. Acknowledging that this change is not a net performance improvement and stopping work on this task. |
💡 What:
Optimized the
_lineBoxCachelookup strategy in_ambientTextLineBox. Instead of unconditionally callingremove(key)and re-insertingkeyon every cache hit, we check if_lineBoxCache.keys.last != key. The map mutation (remove + insert) only executes when promoting a key from an older LRU position.🎯 Why:
In Flutter UI rendering, consecutive rebuilds and layout passes of the same button widget or style repeatedly access the same key. The prior code performed map deletion and insertion on every hit, incurring unnecessary allocation and hashing overhead.
📊 Measured Improvement:
PR created automatically by Jules for task 3299218251434118444 started by @esenmx