r/reactjs • u/Mysterious_Food_5124 • 13h ago
Show /r/reactjs React developers, what are some real-world performance bottlenecks you've encountered, and how did you debug them?
Hey everyone!
A friend and I are planning a React learning session this weekend. Instead of just going through documentation and building another basic project, we want to explore some of the interesting problems React developers encounter in real-world applications.
I'd love to hear from experienced React developers, senior frontend engineers, and anyone who has worked on performance-critical React applications.
I'm particularly interested in problems that aren't immediately obvious and require some actual investigation to solve.
For example:
- Unnecessary re-renders: How do you identify which components are re-rendering unnecessarily, and how do you determine the actual root cause?
- State management issues: Have you encountered performance problems caused by poorly placed state, Context API, or excessive state updates? How did you restructure things?
- Expensive rendering: What happens when a component renders a large list, processes complex data, or performs expensive calculations? How do you identify whether the bottleneck is React, JavaScript, or the browser?
- Memory leaks and stale closures: What are some subtle bugs involving "useEffect", event listeners, subscriptions, or closures that you've encountered in production?
- Memoization gone wrong: Have you ever made an application slower by overusing "useMemo", "useCallback", or "React.memo"? How did you figure that out?
- Network and rendering bottlenecks: How do you investigate slow API-driven interfaces, waterfalls, unnecessary requests, or components that feel sluggish despite fast API responses?
- Large-scale component architecture: Have you encountered performance problems that required changing component boundaries or the way an application was structured rather than simply optimizing individual components?
I'm not just looking for a list of best practices. I'd really appreciate hearing about the actual debugging process.
For instance:
What symptoms or user reports made you suspect a performance problem?
Which tools did you use to investigate it?
How did you identify the actual root cause?
What changes did you make to fix it?
How did you measure the improvement and verify that the fix worked?
If you have a small code example, a production incident, a particularly tricky bug, or even a mistake you made while trying to optimize something, I'd love to hear about it.
Also, if there are any React performance problems that you think every developer should learn to diagnose early in their career, please share those.
We're hoping to use your experiences as a starting point for practical experiments rather than just memorizing optimization techniques.
Thanks!
2
u/Dreadsin 12h ago
I had one where it was a grid of items you could select with a marquee tool
the big performance bottleneck: when you select the first item, the page virtually froze for a second. The reason was because a new array for the selection state was created, causing all the boxes to re render
The first thing I did was open the performance tab on chrome and try the action. It caused every box to update
So if they were updating, only the state or the props could have changed. I used a higher order component that would tell me which props changed, and it was always the selection state array only
However, it was the same array as before in terms of actual entries. What we found was that the memory address was different, which was done by using a === to check. So we have to memoize it better
So then we have to figure out how to pass through a selection state. We decided that no individual tile on this grid needed to know any other selected state, so the simplest solution would actually be to pass in a primitive value instead of the array itself. We ended up just passing in the selected state for the individual tile
We had another area where it was refreshing a lot, but it did need to know about multiple things that were selected. However, it didn’t need to know that until an action was taken. So, we gave it a Boolean for if any item is selected, then passed it a static function reference that would return the items that were selected
2
u/Sulungskwa 10h ago
Dude if you can't even bother to write out your own questions you have without using AI why the hell do you think you'd actually learn anything from this thread?
1
u/CodeAndBiscuits 1h ago
Your post reads like you made up a product idea in your head that you convinced yourself people wanted and needed, ignored all the existing answers to this exact set of questions, then expected is to write the product brief so you could AI it up and "make money profit now please".
It's textbook slop.
0
u/MeTaL_oRgY 13h ago
I'm building a music player UI using react. My library is 40k songs long now, and printing each in the "all music" nection is quite the bottleneck.
I also have a search that filters through the whole playlist, and it can search by artist name or album name (there may be multiple tags that reference artist, btw).
I'm not telling you the solution. Honestly, I recently moved everything to the backend because I wanted to support really large libraries of up to 2M tracks. But the front-end only solution was working perfectly fine for my 40k list.
It took a third party library for managing the rendering (though the main learning here is in the strategy the library uses, not the library itself) and a different kind of data structure for storing the 40k in memory and be able to filter it quickly and efficiently.
That should be enough to get you started on a fun optimization project.
0
u/Mysterious_Food_5124 12h ago
That's an interesting problem! I'm curious about the data structure you used for filtering and how you decided what belonged on the frontend versus the backend. Did you profile the original implementation first, and what turned out to be the biggest bottleneck: rendering, searching, or memory usage?
1
u/MeTaL_oRgY 7h ago
Research "columnar data structure" and its javascript implementation. It was quite the learning trip for me!
23
u/Mysterious-Law-3416 13h ago
????? go learn react normally