perf(gather): Faster shadowDOM testing#3327
Conversation
d1b93bd to
1203736
Compare
| var results = axe.runVirtualRule('nested-interactive', node); | ||
|
|
||
| assert.lengthOf(results.passes, 0); | ||
| assert.lengthOf(results.passes, 1); |
There was a problem hiding this comment.
I have no explanation for why this test wasn't erroring before... There are two applicable nodes in this tree, one passes, the other fails.
There was a problem hiding this comment.
this blew my mind but I gave up trying to understand why
| * @param {Context} | ||
| * @return {Function|null} | ||
| */ | ||
| function getContextFilter(context) { |
There was a problem hiding this comment.
I have no idea what tests to write for this. I'm not sure it's necessary, since PR doesn't change output. It just makes some things faster. If you feel tests are necessary, please let me know and I'll figure something out. Will probably need to put something on the global axe object so that I can spy on stuff.
There was a problem hiding this comment.
You could create a very deep shadow tree that times out the tests with the old code and doesn't now?
There was a problem hiding this comment.
I suppose so... Didn't try that. I'll play around with that for a bit, see if that works.
| return !!vNode.children.find(child => { | ||
| return containsShadowChild(child, otherVNode); | ||
| }); |
There was a problem hiding this comment.
This was the biggest problem. Searching all descendants of vNode instead of just looking at the ancestors of ovetherVNode.
|
Merging #3332 |
Testing if deeply nested shadow DOM nodes are in context can be a very slow operation, especially on sites that make extreme use of shadow DOM (think 30+ layers of nested shadow trees). For a very large part, this is because calling
containsShadowChildthousands of times recursively is very slow.This PR avoids calling
isNodeInContextwhen it isn't necessary (when there are no excluded nodes), and makescontainsShadowChildsignificantly faster by walking down to the root, rather than walking the entire tree.