Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

short circuit DOM node looping when handling events for '*' (all) query selector #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mxriverlynn
Copy link

This is a very small change that may have a very large impact on performance for handling events in low-powered devices and unusually large DOM structures.

The current version of the code, in utils/listener.js file at the matches function, performs a querySelectorAll on the parent node of the node where the event occurred. The list of nodes are then compared against the node on which the event occurred in order to verify that the clicked node should have its events tracked.

this works very well and in general is optimized code.

However, ProdPerfect's auto tracking script uses a * query selector to state, for example, that all clicks on any DOM element should be recorded. In this case, the use of the query selector and loop are not needed. The node was clicked and since all clicked are being recorded, no check is necessary to see if this node should have events recorded.

This pull requests adds a single line of code to the first line of the matches function which will check for the * query selector and immediately return true if it's found.

The net result of this is the elimination of unnecessary DOM traversal, which can have a significant impact on low-power devices and unusually large DOM structures.

Derick Bailey added 2 commits August 13, 2019 09:48
…n looking for events on '*' (all) dom elements. this should provide a performance increase on low-powered devices and on DOM nodes that are unusually large
lib/utils/listener.js Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant