⚡ Optimize nested querySelectorAll loops for tweak buttons - #3
⚡ Optimize nested querySelectorAll loops for tweak buttons#3pauloblikstein wants to merge 1 commit into
Conversation
Previously, `apply()` re-queried the DOM on every call using nested `querySelectorAll`, adding O(N*M) overhead. This update caches the button elements, their keys, and values during initialization into a `tweakButtons` array, allowing `apply()` to iterate linearly over the cached array without touching the DOM tree for querying. Co-authored-by: pauloblikstein <931343+pauloblikstein@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. |
💡 What:
Optimized the event listeners and the
apply()function for the tweak buttons. Instead of re-querying the DOM insideapply()using nestedquerySelectorAll, we now cache the buttons and their associated keys/values during initialization in an array (tweakButtons) and iterate over it directly.🎯 Why:
The previous implementation used nested
querySelectorAllinside theapply()function, which is called every time a tweak button is clicked. This caused unnecessary O(N*M) DOM traversal overhead because the DOM structure is static and does not change.📊 Measured Improvement:
I created a benchmark using Puppeteer to simulate 10,000 click operations that trigger the
setTweakandapplylogic.PR created automatically by Jules for task 10367792058443112342 started by @pauloblikstein