DEV Community

Cover image for Optimizing React Table Rendering By 160x !!!

Optimizing React Table Rendering By 160x !!!

Navneet Kumar Singh on May 09, 2024

React is "generally" a performant framework.. notice the "" on generally, Yeah that is because at times in react land you do feel very limited beca...
Collapse
 
cmacu profile image
Stasi Vladimirov

Or alternatively you could’ve used virtual DOMless framework or VueJS where half of the DOM doesn’t get re-rendered just because the cursor was moved…
The reality is that React is outdated and full of idiosyncrasies such as useEffect, useCallback, useMemo (and more incoming with the latest release) just to somehow keep it working. We need to let this dinosaur die so the web can move forward.

Collapse
 
miketalbot profile image
Mike Talbot ⭐

There is no DOMless framework on a web browser, it's how the browser works. This problem isn't to do with virtual DOM, it's a problem that needs to be solved with virtualization in all cases due to the number of individual DOM nodes created for a large table.

Collapse
 
navneet7716 profile image
Navneet Kumar Singh

true

Collapse
 
ekeijl profile image
Edwin • Edited

React 19 Some version after React 19 should prevent the need for useMemo() or useCallback(), so developers don't need to think about those anymore. Besides, the concept of memoization has been around for ages, it requires some thinking but it's not THAT complicated.

The newly introduced hooks are of a completely different nature and completely optional. In fact, they're add features for handling form state and promises, things that were long overdue.

It's fine that you have a preference for a different library, but I think React 19 is actually moving things forward here.

Edit: learned that the optimizing compiler for React will be added somewhere after version 19, but it's coming!

Collapse
 
navneet7716 profile image
Navneet Kumar Singh

Haven't tried the new 19, will give it a go I am playing with some other things at the moment at work I have to work with react 17 so 😅

Collapse
 
navneet7716 profile image
Navneet Kumar Singh

😂 true but for one page we can't change the stack

Collapse
 
chinmaymoghe profile image
Chinmay

Just use Svelte, Solid, Qwik, Vue and stop it with React....why use React with its runtime shipped to browser ? On top of it it's just a lib, no state management, which is nuts , check out Svelte it's almost got everything, transitions, state management, animations...

Collapse
 
hackape profile image
hackape • Edited

I’m a svelte fanboy. But using svelte doesn’t magically solve the problem in this post. Yeah re-render is avoided but keeping a crazy amount of nodes in your DOM is problematic. You’ll need virtualized list anyway.

Collapse
 
navneet7716 profile image
Navneet Kumar Singh

yep!

Collapse
 
navneet7716 profile image
Navneet Kumar Singh

You are right about most of it but React is still pretty good.

Collapse
 
nabous profile image
Mohamed Nabous

I remember facing this issue on a project and the boss said use intersection observer to hide and show the dom of each row and write the code from scratch...
I did it and it worked... But i know i should have used a library 😅

Collapse
 
navneet7716 profile image
Navneet Kumar Singh

Yeah the lib is great, but also would be really cool to do it from scratch.

Collapse
 
stuartambient profile image
stuartambient • Edited

React Virtuoso is a good choice for windowing / virtualization. AG Grid also does virtualization out of the box.

Collapse
 
navneet7716 profile image
Navneet Kumar Singh

oh didn't know about it thanks for letting me know

Collapse
 
rixki profile image
Muhammad Rizkiansyah

question:
i've already try to use virtual list things, for example from 100k item, the component require me to setup how much the height specifically... i think if we use it on fullscreen size table, the height need to be collected from ref, but is there any module to apply the size automatically just like using flex: 1 ?

Collapse
 
navneet7716 profile image
Navneet Kumar Singh

yeah the package itself provieds a component called as AutoSizer for that purpose.

Collapse
 
akhileshpandeyji profile image
Akhilesh Pandey

Pagination can also help here I think, if not needed then this could be a better option.Also It would be great if this dynamic loading of rows can be achieved from scratch as we don't know whether this 'react-window' library offers best performance and optimization.

Collapse
 
navneet7716 profile image
Navneet Kumar Singh

yeah you are right but pagination was not the requirement here we wanted all the data in one go 😅.

Collapse
 
sliter profile image
sliter

I had to go through similar thing to make my demo work
sliterok.github.io/opfs-demo/
I didn't polish it much, looks like you have to press the init table button 2 times for it to work

Collapse
 
navneet7716 profile image
Navneet Kumar Singh • Edited

Nice !!

Collapse
 
cgatian profile image
Chaz Gatian

Lol 49 seconds, what?! That might be a record.

Collapse
 
navneet7716 profile image
Navneet Kumar Singh • Edited

🥲 not something to be proud of

Collapse
 
amrita88 profile image
Amrita

Whoa 😮

Collapse
 
navneet7716 profile image
Navneet Kumar Singh

😂😂

Collapse
 
ngocxxu profile image
Quach Ngoc • Edited

So that I cannot apply react-window for pagination right, this case of your blog just use for unlimit scrolling table right?

Collapse
 
navneet7716 profile image
Navneet Kumar Singh

yep because we didn't wanted pagination.