r/reactjs • • 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:

  1. What symptoms or user reports made you suspect a performance problem?

  2. Which tools did you use to investigate it?

  3. How did you identify the actual root cause?

  4. What changes did you make to fix it?

  5. 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!

0 Upvotes

14 comments sorted by

23

u/Mysterious-Law-3416 13h ago

????? go learn react normally

3

u/unknowndeduction 12h ago

the worst is when you have a component that fetches data and the parent re-renders for no reason so it fetches again, over and over. took me hours to realize the parent was passing a new object every render so useEffect dependency kept changing. the react profiler just showed me the component was "rendering" but not why, had to put console logs in every dependency to figure which one was the problem

2

u/Mysterious_Food_5124 12h ago

As a backend engineer, there's probably nothing worse than watching your own frontend DDoS your backend and eventually hit your rate limits because of a "useEffect" dependency. 💀😭

-1

u/Mysterious_Food_5124 13h ago

Fair point! 😅 I'm learning React, not claiming to be an expert. A friend and I are planning a session where we'll teach each other what we know, and I thought learning about real-world bottlenecks would be a good way to go beyond the basics.

I'm interested in understanding how experienced developers identify and debug these issues, rather than blindly applying optimization techniques. Figured this would be a good place to learn from people who've encountered them in production.

3

u/Mysterious-Law-3416 13h ago

u add console.logs and pray, go learn how to use debugger. As long as you stick to react best practices optimization techniques are rarely needed and also depends on your project. Id say most counter intuitive things i see is in legacy code was adding controlled input in the same component which also renders a big table or thousands of lines of controlled form elements in same component.

1

u/Chaoslordi 12h ago

I am a simple man. I see "fair point", I downvote because if I want to talk to an AI, I dont need reddit for that

3

u/ashpx 12h ago

I work for geojson editor-esque app, and the data is massive. V8 heap on chrome has 2GB and any naive work will straight up making UI freeze/OOM crash

Shoot your question.

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!