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

feat: Improve performance of ByRole in waitFor* #590

Merged
merged 3 commits into from May 28, 2020

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented May 27, 2020

What:

Closes #552

Why:

Error diagnostics are the most expensive part of ByRole and are completely wasted in successful findBy queries.

findByRole-profile

In the test profiled we spent 11.5 ms in queryAllByRole and 180ms in getElementError.

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 to false 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 the
    docs site
  • [ ] I've prepared a PR for types targeting
    DefinitelyTyped
  • Tests:
  • Ready to be merged

@eps1lon eps1lon requested a review from kentcdodds May 27, 2020 16:01
@codesandbox-ci
Copy link

codesandbox-ci bot commented May 27, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a184166:

Sandbox Source
elated-worker-bsnh9 Configuration
sweet-hooks-4j8tq Issue #552

kentcdodds
kentcdodds previously approved these changes May 28, 2020
Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty hacky, but I can't think of a better way to do this either. Thanks for all your investigation on this and helping make it much better!

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet!

@kentcdodds kentcdodds merged commit 709044b into testing-library:master May 28, 2020
@kentcdodds
Copy link
Member

🎉 This PR is included in version 7.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getByRole("progressbar") is pretty slow
2 participants