Ask HN: How to performance test React webapps for rendering speed regressions?

79 points by janci5243 5 years ago

As React webapps get large and start to contain a lot of complex components, they often do not perform well and manifest low FPS in browser. As a result, engineers add strategies such as memoization (React.memo, shouldComponentUpdate) to avoid unnecessary computation, however they logic is fragile to code changes.

Is there a way to automatically test performance (maybe in terms of FPS) of React applications regularly in CI pipelines? Any tools for this out there?

iamleppert 5 years ago

For frontend performance: record the frame rate (via requestAnimationFrame, look at simple frame rate counters), memory, count of DOM nodes on the page during each of your integration tests as a good start. You can get a lot of this via window.performance and memory info you need to pass an extra flag into chrome headless.

It’s also useful to instrument this in your production environment (called real user metrics) for some % of user sessions and combine it with more synthetic tests.

The backend is of course really easy, just measure request times (min/avg/max) and time to first byte.

Edit: Don’t know why I’m being downvoted for this answer? Lol

  • vnchr 5 years ago

    Thanks a lot, this is something I was specifically looking for!

  • geezerjay 5 years ago

    Don't mind the downvotes. Thank you for taking the time to post such an insightful post.

  • tehlike 5 years ago

    +1 on instrumenting production. Best way to find out regressions, and future optimizations.

ejwessel 5 years ago

I don't do front end, but I asked my team and they linked me to:

https://medium.com/@paularmstrong/twitter-lite-and-high-perf...

https://github.com/markerikson/react-redux-links/blob/master...

Might be worth going through. Hopefully they're useful.

jbaudanza 5 years ago

Before you spend time profiling a performance issue, make sure you're using the production build of React. The development build is significantly slower. It sounds obvious, but I've made the mistake of trying to optimize performance issues that simply didn't exist in production.

pspeter3 5 years ago

At Asana, we actually test performance in production with a A/B test split. We use Interana (but any data aggregator would work) to analyze the results. Trying to measure the regressions in a sandbox did not match our Real User Metrics (RUM). In order for this to work though, you need to develop a strong mental model of React performance so you can optimize it further.

  • StreamBright 5 years ago

    Do you have a blog post or something like that about React performance or the mental model you got? It would be an interesting read.

CallidaVorhis 5 years ago

A few ideas:

- https://firebase.google.com/docs/perf-mon/get-started-web (this is a new feature released by Google. Luckily you don't need Firebase to use this. https://www.youtube.com/watch?v=KYYjdWSrRjI&t is a good tutorial on wiring your app up)

- https://reactjs.org/docs/perf.html

- lighthouse by Google

You could just run lighthouse on your app periodically for an in depth audit on your site. That way you wouldn't need to slow down your builds with a test (not sure what's best practice here. Just trying to throw out some basic ideas)

mmckelvy 5 years ago

> As React webapps get large and start to contain a lot of complex components, they often do not perform well and manifest low FPS in browser.

Is this something you have actually experienced? Can you cite an example of running into this issue? I've built fairly complex UIs with React (tables with nested dropdowns, financial statements with a lot of data points, dynamic charts / graphs, elements with animations, etc. and haven't run into this issue.

The only time I've seen people have trouble w/ performance is when they use something like Redux or Apollo on top of React. The problem in those cases of course is Redux or Apollo, not React itself.

  • badestrand 5 years ago

    I'm not OP but at work we have a actually not-so-complex website that takes a full second to render a new page when switching, on my MacBook. On production and without loading anything via the network.

    I blame it on create-react-app, which feels very very bloated to me. Whenever I write React from scratch it feels super performant, even with Redux and much more complex layouts than the page I mentioned.

    • petetnt 5 years ago

      Hi,

      as a Create React App maintainer I'd love if you could share some scenarios where CRA itself would cause performance issues. CRA itself is mostly just developer tooling and every other feature is opt-in. The team and many contributors (including people on WebPack team) have spent quite a lot of time on optimizing the production builds CRA produces; building an React only app won't have much else than React and React-DOM itself, while we also automatically do more advanced things like bundle spitting too.

    • zackify 5 years ago

      Create React app includes almost no extra client facing code other than react. There is an issue with how you made the application.

    • ggregoire 5 years ago

      That's like saying VSCode makes your site slower.

mychael 5 years ago

Many of the answers on this post are confusing web performance for rendering speed.

Equiet 5 years ago

Looking for the same. Ideally something that integrates well with Storybook or Testcafe.