-
Notifications
You must be signed in to change notification settings - Fork 776
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
Use virtualNode as caching space #1096
Comments
In addition to performance benefits, this also decreases our reliance on global methods which is a big bonus. Further more, we could start thinking about constraining matches/evaluate functions from having access to the DOM at all, which could be a big benefit for making sure custom rules can't do anything malicious. |
We had a quick chat about this and I'm of the opinion we may be better off using an existing memoization tool and just wrapping our existing functions. For example: const memoize = axe.imports.memoize
axe.utils.isFocusable = memoize(function (node) {
// is focusable computation here
}) This leaves the "virtual DOM" abstraction alone and requires very little effort to achieve the same performance win. NOTE - the memoization tool we use should rely on a |
@stephenmathieson That would mean axe-core keeps all tested nodes in memory pretty much permanently. I don't think that's ideal. |
@WilcoFiers maybe we fork something like https://www.npmjs.com/package/@emotion/weak-memoize and expose the We could do something like: axe.run = () => {
memoizeThing.clear()
// normal axe.run() logic
} |
@stephenmathieson whatever solution we choose should clear the cache at the end of the run call, so the pseudo code should read
|
Let's memoize (with clearing cache)! |
Do this for #908 |
Axe-core is increasingly moving away from directly working with the DOM and abstracting things out. Especially with the introduction of shadow DOM, many of the common methods are no longer in use, such as the usual querySelectorAll, most DOM walking (parentNode, children, etc.), getRoot() and quite a bit more.
One of the problems we have with axe-core is that there is no data sharing between check evaluate calls and between matches. Each runs in its own context and can't take any data from other evaluate / matches calls. This means that many things get computed over and over again. Axe-core does very little in terms of caching. When it comes to querying the DOM for the same thing hundreds of times, or computing the background of the same element thousands of times, these things add up.
The solution: We start putting memoization methods onto the virtualNode. For instance, instead of doing:
axe.commons.text.accessibleTextVirtual(virtualNode)
we would also allowvirtualNode.accessibleText()
which when called the first time would callaccessibleTextVirtual
, and would cache the result for any subsequent calls. I think that would save a bunch of time. Here's a list of methods I think we should move onto the virtualNode:The text was updated successfully, but these errors were encountered: