-
Notifications
You must be signed in to change notification settings - Fork 785
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
feat(get-element-stack): performant api to replace document.elementsFromPoint #1842
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicky stuff. Will review in depth at a later date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor nitpicks and micro performance suggestions. Overall, good work here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Half a review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add support for the other type of replaced objects - see comment
We decided to hold off on supporting CSS rotation for now and add it as a separate PR / function. |
Just making a pr with the new api for now since it's quite big in terms of code size. Once this is merged I'll make another pr to use it.
The code essentially does the following:
I also added cache functions to virtual node as we do these lookups a ton throughout the codebase.
In terms of performance. Running this new function on every node on https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template compared to
document.elementsFromPoint
and ourcolor.getRectStack
function (which is what usesdocument.elmentsFromPoint
under the hood for color-contrast checks), the average of 5 runs are:color.getRectStack
: 143.47900002030656msdom.getElementStack
: 53.457000001799314msRunning it on https://web.archive.org/web/20190613132353/https://giveawaylisting.com/ (have to use web archive result now that the site is going down) results in:
color.getRectStack
: 143147.4000000162msdom.getElementStack
: 2190.5150000122376msNOTE: Jason's suggestion saved ~20% time (500ms on giveawaylistings.com)
Reviewer checks
Required fields, to be filled out by PR reviewer(s)