Skip to content

Add the framework required to run component stress tests #5929

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

Merged
merged 76 commits into from
Apr 22, 2025

Conversation

hectahertz
Copy link
Contributor

@hectahertz hectahertz commented Apr 15, 2025

Changelog

New

This PR adds the framework required to run component stress tests and a couple of examples.

The tests run on Storybook and measure the time it takes for a component to react to a state change.

This is how one of them looks like:

Screen.Recording.2025-04-15.at.21.10.00.mov

I tried to make the code self explanatory but I'll give a brief overview of how the pieces fit together here.

StressTest.tsx is a helper component to be used in Storybook, that takes care of all the performance measuring part of the stress tests. It has a very simple API so that defining the tests is as simple as possible.
It uses afterframe and a React state update to do this. We trigger a state update, which the component will react to and rerender appropriately according to the test defined. The afterFrame library calls the function when the next frame starts and measures the elapsed time. The reasoning behind this approach is well explained in this article.

[Component].stress.stories.tsx contain the stress tests for a few components. The components will react to the state change by interacting with the count prop provided in the render function. This reaction is what the stress test will measure.

stress-tests.yml defines the workflow that runs the stress tests. It runs the Playwright tests against the Storybook server and stores the results in a file. This file is stored in the cache and compared to the previous results. Each commit will generate a new result in the cache.

If the result of any commit is slower than the alert threshold defined there, the workflow will fail and a comment will be added to the commit with the results.

Screenshot 2025-04-15 at 20 46 39

StressTests.test.ts is where the Playwright tests are defined. The tests just run the Storybook story and grab the mean result from them.

stress-test-reporter.ts gets the results from the Playwright tests and stores them in a file, in a format that benchmark-action/github-action-benchmark expects.

FAQ

How much of a stable environment do you need for this to be reliable?

So far, defining runs-on: ubuntu-latest-4-cores on the workflow has been very reliable. Running the tests locally is also very consistent from run to run but, as you can imagine, it will only be useful to compare numbers between runs on the same hardware.

How accurate is it at detecting regressions?

Very accurate according to my tests. Here's an example of enabling and disabling CSS modules on ActionList:

Screen.Recording.2025-04-14.at.19.39.26.mov

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

@francinelucca francinelucca self-requested a review April 15, 2025 20:50
Copy link
Member

@francinelucca francinelucca left a comment

Choose a reason for hiding this comment

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

Very excited for this! Just two non-blocking questions

@lesliecdubs lesliecdubs requested a review from joshblack April 17, 2025 03:46
Copy link
Member

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together! Really the only question I had with this was around StressTest and afterframe and what differences there are between setting up a harness with this versus using something like Profiler with React.

@github-actions github-actions bot requested a deployment to storybook-preview-5929 April 18, 2025 15:34 Abandoned
@hectahertz hectahertz added this pull request to the merge queue Apr 22, 2025
Merged via the queue into main with commit 294dac3 Apr 22, 2025
45 checks passed
@hectahertz hectahertz deleted the hectahertz/stress-test branch April 22, 2025 18:03
@primer primer bot mentioned this pull request Apr 22, 2025
hectahertz added a commit that referenced this pull request May 20, 2025
Co-authored-by: Jon Rohan <yes@jonrohan.codes>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy