Urgent.News

What's breaking now, across thousands of outlets.

Tech

I Benchmarked Five Ways to Speed Up a Slow React Table. Two of Them Did Nothing.

A table of 4,000 rows with a filter box above it. You type "acme" and the cursor lags behind your fingers. Every frontend developer hits this shape eventually, and the advice for fixing it is remarkably consistent: wrap the row in React.memo . That advice is where I started too, and it turns out to be close to worthless on its own. So rather than argue about it, I built a harness that measures…

Five methods to enhance the performance of a slow React table were examined, with two yielding no improvement. The initial approach was to wrap the row in `React.memo`, but this alone offered only a negligible 13ms reduction. Another method involved utilizing `memo`, `useCallback`, and `useMemo` together, which reduced the render time to 47ms, a 3.5x improvement.

However, two crucial details were overlooked: `handleSelect` should accept the `id` argument directly rather than closing over it, and the dependency array for `useMemo` should accurately reflect the dependencies to avoid unnecessary recomputation. An intriguing result was variant 4, which achieved the fastest render time of 0.4ms by omitting the table's filtering capability.

This occurred because the table's children were created outside the parent component responsible for rendering it, effectively bypassing the need for re-rendering. While this pattern can be beneficial for components whose state doesn't affect expensive subcomponents, it's ineffective for filtering scenarios where the filtered data is required.

Thus, the optimal solution combines variations 2 and 3, implementing `useCallback` and `useMemo` correctly to achieve significant performance enhancements in React tables.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Monday 21 September →