feat: Improve performance of ByRole in waitFor* #590
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What:
Closes #552
Why:
Error diagnostics are the most expensive part of
ByRole
and are completely wasted in successfulfindBy
queries.In the test profiled we spent 11.5 ms in
queryAllByRole
and180ms
ingetElementError
.Profile on master: https://drive.google.com/file/d/1tagr32Pzo7eU4MoEJZcq-4h6tgTBFDkA/view?usp=sharing
Profile with this PR: https://drive.google.com/file/d/18y3fnD9f46rU6dR-dPvIM52zdNog16Ll/view?usp=sharing
How:
Add a variable at the module scope that controls whether we run these expensive diagnostics. In
waitFor
we flip this tofalse
when running the given callback.This reduces the time spent in
getElementError
to 2ms (only pretty printing the DOM).This means we improve runtime by (in this particular instance) 94%.
The issue is that on timeout the user is left without useful diagnostics. We could run the callback again with expensive diagnostics enabled but this would make the passed
timeout
less exact. Would that be a problem?Checklist:
[ ]Documentation added to thedocs site
[ ]I've prepared a PR for types targetingDefinitelyTyped