How to Show 10 Million of Something: Frontend Performance Beyond Memoization

Rate this content
Bookmark

When discussing frontend performance, there are usually two topics: Lighthouse scores, and rerenders. But when working on applications that deal with large amounts of data and pagination is not an option, entirely different categories of optimizations become necessary.

Through the case study of Axiom's trace viewer, we will examine the solutions that keep your application running (and running fast!) each time your data size grows by an order of magnitude. 

This talk has been presented at React Day Berlin 2024, check out the latest edition of this React Conference.

FAQ

Nadia Makarovic is recommended for resources on optimizing React rendering performance.

Recommended tools for optimizing web vitals in the React ecosystem include Next.js, Remix, Astro, and Quick.

The first step is to measure compute, memory, and network performance to identify bottlenecks before starting optimization.

Chris faces the challenge of dealing with enormous amounts of data, such as tens of thousands or millions of items, in React applications.

Chunking data and using cursor-based pagination was implemented to manage large data sets effectively.

Rendering performance focuses on optimizing how the application performs while users are interacting with it, rather than just on load times.

The Trace Viewer app had memory issues due to using MobX, which wrapped proxies around each object.

Constant evaluation of bottlenecks and making incremental improvements to performance-critical paths is recommended to maintain a culture of performance awareness.

The strategy used was to keep spans as regular JavaScript objects outside of MobX and React, using MobX only for smaller state updates.

The most common conversation around performance in React apps is web vitals, which determine how fast the app loads and becomes interactive.

Christopher Ehrlich
Christopher Ehrlich
29 min
16 Dec, 2024

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Today's Talk focused on performance optimization in React apps, specifically in handling and rendering enormous amounts of data. The speaker discussed various techniques and tools to achieve better performance, such as optimizing data relay, rendering, data processing, memory usage, and denormalization. They also highlighted the importance of optimizing network performance, payload size, and request handling. The Talk emphasized the need to measure before optimizing, focus on bottlenecks, and make small improvements that actually benefit users. Overall, the Talk provided valuable insights and recommendations for improving performance in React apps.

1. Performance in React Apps

Short description:

Today, I'll discuss the specific type of performance I was looking for in React apps. While web vitals are important, users care more about performance during usage. Rendering performance can be optimized with resources like Nadia Makarovic's writing and upcoming React Compiler. For heavy runtime compute, you can explore RustWasm. I'll focus on dealing with enormous amounts of data. We'll start with a demo of Axiom's Trace Viewer, a performant app with over a million spans. Now, let's talk about achieving similar results.

Hello, today, I'm going to talk about performance in React apps. Now, when I started working on the project that I'll discuss in this talk, I found that there are many resources on React performance and frontend performance in general. But most of them were not actually all that relevant to the specific type of performance that I was looking for.

Probably the most common conversation around performance is the one of web vitals. Now, web vitals are super important. They determine how fast your app loads, how fast it is interactive, and so on. And nowadays, there are many great solutions for this. If you're in the React ecosystem, you can try Next.js or Remix. And there are also many other great tools, such as Astro or Quick. However, I mostly work on what I would call applications or dashboards, so I find that users don't actually care that much how fast the site loads as long as it's reasonably fast. And they care much more about how it performs once they're using it.

That brings us to the second topic that is discussed quite often, which is rendering performance. This is a topic I deal with fairly often, but I find that there are many excellent resources on this nowadays. For example, I'd recommend the writing of Nadia Makarovic. I found that once you know how to optimize React a little bit, it gets quite fast, and the entire problem of rendering performance is mostly solved. Additionally, React Compiler is coming soon, which will help us even more with this. And then, of course, there are other frameworks that focus even more on rendering performance, such as Solid.js.

Another topic on which there are already plenty of resources is the one of having very heavy runtime compute. And there are many things you can do here. One of them, for example, is to write RustWasm, and if you're interested in that sort of thing, then Ken Wheeler has some really good talks about this topic. But the kind of performance that I found myself struggling with is how to deal with enormous amounts of data, tens of thousands, hundreds of thousands, or even millions of items. Now, as this tweet here shows, I think a lot of people don't understand why you would ever want to do this, and it's a very reasonable question, which is why I want to talk about it today. So, what we're looking at today is how to show 10 million of something.

Let's start with a demo. The application we're going to look at today is Axiom's Trace Viewer. It has a fairly normal feature set for this kind of application. So, for example, you can page through error spans, you can look at the details of various spans, and if a span is particularly slow, you can take a look at how it compares to usual spans of that type. Of course, it also has many other features, but the main point I want to show is that it's quite performant, even though we currently have a Trace Open with just over a million spans, and this is in local host, which has quite a bit of overhead compared to running the app in production.

So, now that you've seen the app, let's talk about how you can achieve something like this. Some quick details about me.

2. Handling 10 Million Items

Short description:

My name is Chris. I recommend avoiding handling 10 million items as it takes a lot of time and makes the code base more difficult. Listen to your customers and develop against real data of a similar scale. Use pagination, streaming, or aggregation. Negotiate requirements if asked to show millions of items. Measure before optimizing, focusing on compute, memory, and network. Rethink the architecture to improve capability. Initial errors didn't originate in the front end.

My name is Chris. I work for Axiom, which is the application you just saw, and in the open source world, I'm known for some contributions to CreateT3App and TRPC and some other projects.

So, how do you handle 10 million items? Well, my recommended thing to do is just to not do it. Now, of course, this is not very helpful advice, but I want to be serious here. Try to avoid it. This type of work takes a lot of time that you could spend on fixing bugs, writing new features, and so on, and it also makes your code base much more difficult for the next person to work on.

I think many of us love this idea of solving very interesting technological problems, but what you need to think about is, is this the best way you can spend your time to make your users' lives better? The way to know whether you need this or not is to listen to your customers and see what their frustrations are. The other thing that can help you figure out if you need this or not is to consistently develop against a real server with real data of a similar scale as your biggest users have.

So, if you should avoid it, how can you do that? It's going to depend on your situation, but there's many options here. You can use pagination, so getting in 10 or 20 or 100 results at a time. You can use streaming, so only getting in the specific results that are currently needed. Or maybe you don't even need the individual items, you just need to run some sort of aggregation on them. In that case, you can do it server-side, or in many cases, even in the database. And the final thing I want to point out is that if your product owner asks for this, I would really suggest to negotiate the requirements and figure out why it is that they want this. Maybe they're actually presenting you with an XY problem, and there's really a much better solution, such as one of the three things above.

But let's say you have negotiated, you have thought about this, you have considered the alternatives, and you've come to the conclusion that the only way to make your app good is to show millions of items at a time. What do you do now? The first thing that's very important is to measure before you start optimizing. There's a good chance that you're completely wrong about where your bottlenecks are. There are three main things to measure, compute, memory, and network, and we'll look at each of them later on.

So now that we're through the introduction, let's talk about the specific things that helped us out in our situation. I'm going to omit some implementation details here, so I'll show a few things that don't one-to-one represent how Axiom behaves in production. But these details are very specific to our situation, and I think we'll end up with a more useful talk this way.

Here's the starting point. It's late 2023, and tracing in Axiom works great, up until about 5000 spans. But we didn't know that last part at the time, because why would anybody ever want to create traces that big? And then we launched a new pricing plan, and people realized that they could use our tracing as effectively a profiling tool without incurring huge costs, and so they did, and we couldn't handle it. This is what happened if you tried to open a trace with even just 10,000 spans. I think you can see from the error message that we hadn't even considered this possibility or this way of failing.

After some quick investigation, we realized that we really had to rethink the entire architecture of the trace viewer. So let's look at what we did step by step to improve our capability by several orders of magnitude. Now this initial set of errors didn't actually originate in the front end.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

A Guide to React Rendering Behavior
React Advanced 2022React Advanced 2022
25 min
A Guide to React Rendering Behavior
Top Content
This transcription provides a brief guide to React rendering behavior. It explains the process of rendering, comparing new and old elements, and the importance of pure rendering without side effects. It also covers topics such as batching and double rendering, optimizing rendering and using context and Redux in React. Overall, it offers valuable insights for developers looking to understand and optimize React rendering.
Speeding Up Your React App With Less JavaScript
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Top Content
Watch video: Speeding Up Your React App With Less JavaScript
Mishko, the creator of Angular and AngularJS, discusses the challenges of website performance and JavaScript hydration. He explains the differences between client-side and server-side rendering and introduces Quik as a solution for efficient component hydration. Mishko demonstrates examples of state management and intercommunication using Quik. He highlights the performance benefits of using Quik with React and emphasizes the importance of reducing JavaScript size for better performance. Finally, he mentions the use of QUIC in both MPA and SPA applications for improved startup performance.
React Concurrency, Explained
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
Watch video: React Concurrency, Explained
React 18's concurrent rendering, specifically the useTransition hook, optimizes app performance by allowing non-urgent updates to be processed without freezing the UI. However, there are drawbacks such as longer processing time for non-urgent updates and increased CPU usage. The useTransition hook works similarly to throttling or bouncing, making it useful for addressing performance issues caused by multiple small components. Libraries like React Query may require the use of alternative APIs to handle urgent and non-urgent updates effectively.
The Future of Performance Tooling
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Today's Talk discusses the future of performance tooling, focusing on user-centric, actionable, and contextual approaches. The introduction highlights Adi Osmani's expertise in performance tools and his passion for DevTools features. The Talk explores the integration of user flows into DevTools and Lighthouse, enabling performance measurement and optimization. It also showcases the import/export feature for user flows and the collaboration potential with Lighthouse. The Talk further delves into the use of flows with other tools like web page test and Cypress, offering cross-browser testing capabilities. The actionable aspect emphasizes the importance of metrics like Interaction to Next Paint and Total Blocking Time, as well as the improvements in Lighthouse and performance debugging tools. Lastly, the Talk emphasizes the iterative nature of performance improvement and the user-centric, actionable, and contextual future of performance tooling.
How React Compiler Performs on Real Code
React Advanced 2024React Advanced 2024
31 min
How React Compiler Performs on Real Code
Top Content
I'm Nadia, a developer experienced in performance, re-renders, and React. The React team released the React compiler, which eliminates the need for memoization. The compiler optimizes code by automatically memoizing components, props, and hook dependencies. It shows promise in managing changing references and improving performance. Real app testing and synthetic examples have been used to evaluate its effectiveness. The impact on initial load performance is minimal, but further investigation is needed for interactions performance. The React query library simplifies data fetching and caching. The compiler has limitations and may not catch every re-render, especially with external libraries. Enabling the compiler can improve performance but manual memorization is still necessary for optimal results. There are risks of overreliance and messy code, but the compiler can be used file by file or folder by folder with thorough testing. Practice makes incredible cats. Thank you, Nadia!
Optimizing HTML5 Games: 10 Years of Learnings
JS GameDev Summit 2022JS GameDev Summit 2022
33 min
Optimizing HTML5 Games: 10 Years of Learnings
Top Content
Watch video: Optimizing HTML5 Games: 10 Years of Learnings
PlayCanvas is an open-source game engine used by game developers worldwide. Optimization is crucial for HTML5 games, focusing on load times and frame rate. Texture and mesh optimization can significantly reduce download sizes. GLTF and GLB formats offer smaller file sizes and faster parsing times. Compressing game resources and using efficient file formats can improve load times. Framerate optimization and resolution scaling are important for better performance. Managing draw calls and using batching techniques can optimize performance. Browser DevTools, such as Chrome and Firefox, are useful for debugging and profiling. Detecting device performance and optimizing based on specific devices can improve game performance. Apple is making progress with WebGPU implementation. HTML5 games can be shipped to the App Store using Cordova.

Workshops on related topic

React Performance Debugging Masterclass
React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Top Content
Featured WorkshopFree
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
Building WebApps That Light Up the Internet with QwikCity
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
Miško Hevery
Miško Hevery
Building instant-on web applications at scale have been elusive. Real-world sites need tracking, analytics, and complex user interfaces and interactions. We always start with the best intentions but end up with a less-than-ideal site.
QwikCity is a new meta-framework that allows you to build large-scale applications with constant startup-up performance. We will look at how to build a QwikCity application and what makes it unique. The workshop will show you how to set up a QwikCitp project. How routing works with layout. The demo application will fetch data and present it to the user in an editable form. And finally, how one can use authentication. All of the basic parts for any large-scale applications.
Along the way, we will also look at what makes Qwik unique, and how resumability enables constant startup performance no matter the application complexity.
Next.js 13: Data Fetching Strategies
React Day Berlin 2022React Day Berlin 2022
53 min
Next.js 13: Data Fetching Strategies
Top Content
WorkshopFree
Alice De Mauro
Alice De Mauro
- Introduction- Prerequisites for the workshop- Fetching strategies: fundamentals- Fetching strategies – hands-on: fetch API, cache (static VS dynamic), revalidate, suspense (parallel data fetching)- Test your build and serve it on Vercel- Future: Server components VS Client components- Workshop easter egg (unrelated to the topic, calling out accessibility)- Wrapping up
React Performance Debugging
React Advanced 2023React Advanced 2023
148 min
React Performance Debugging
Workshop
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
High-performance Next.js
React Summit 2022React Summit 2022
50 min
High-performance Next.js
Workshop
Michele Riva
Michele Riva
Next.js is a compelling framework that makes many tasks effortless by providing many out-of-the-box solutions. But as soon as our app needs to scale, it is essential to maintain high performance without compromising maintenance and server costs. In this workshop, we will see how to analyze Next.js performances, resources usage, how to scale it, and how to make the right decisions while writing the application architecture.
Maximize App Performance by Optimizing Web Fonts
Vue.js London 2023Vue.js London 2023
49 min
Maximize App Performance by Optimizing Web Fonts
WorkshopFree
Lazar Nikolov
Lazar Nikolov
You've just landed on a web page and you try to click a certain element, but just before you do, an ad loads on top of it and you end up clicking that thing instead.
That…that’s a layout shift. Everyone, developers and users alike, know that layout shifts are bad. And the later they happen, the more disruptive they are to users. In this workshop we're going to look into how web fonts cause layout shifts and explore a few strategies of loading web fonts without causing big layout shifts.
Table of Contents:What’s CLS and how it’s calculated?How fonts can cause CLS?Font loading strategies for minimizing CLSRecap and conclusion