DEV Community

Discussion on: Stop returning NULL components

Collapse
 
sergey profile image
sergeyv

The article desperately needs a test to prove the point being made. How much is "a lot of performance"? Half a percent? Fifty percent? Is it only measurable if you render thousands of widgets or just a few?

Collapse
 
sergey profile image
sergeyv • Edited

Ok, wrote a quick test app myself: when rendering 125.000 widgets the difference is 450ms for the "outside check" option and ~2000ms when doing the check inside the component, which is quite significant.

For 1000 widgets, it's ~60ms vs ~70ms and is within the error margin. Maybe just don't render 100k widgets at once :)

github.com/sergeyv/inside-outside


UPDATE: Note to self: never do performance testing on a development build :) On a production build the difference is much smaller: for 125K widgets it's 350ms "outside" versus 450ms "inside". I even went ahead and scaled it to 1.000.000 widgets, the results are ~3s vs ~5s.

I have a feeling that, in a real application, there's a very limited number of scenarios where the two approaches could show any measurable difference.

Collapse
 
ucvdesh profile image
Daniel Silva

Well yeah, but that's for a really simple example app, now imagine a middle-high class app with a lot of states, fetching to the server, displaying other things...

Thread Thread
 
sergey profile image
sergeyv

For a "real app" the difference will likely to be much less, exactly for the reason that it does many other expensive things. The test app does almost nothing but creating hundreds of thousands of widgets, so the difference is exaggerated.

A real-life example: Imagine you have cheap nails for 1 cent each and more expensive at 10c each. A ton of cheap nails would cost, say, $10K and a ton of the expensive ones will be $100K, which is a huge difference.

But if you use the nails to build some nice furniture - you only need a few dollars worth of nails in either case and the cost of the nails in the final product's price will be minuscule in either case and maybe some other considerations may become more important.

Collapse
 
asyrialak profile image
Andrew Syriala

Does it affect the lighthouse score in any measurable way?

Thread Thread
 
sergey profile image
sergeyv

Does your app render tens or hundreds of thousands of widgets conditionally at the same time? If it does then yes, it will affect the score. The common wisdom is to avoid rendering that many widgets at once though.

I quickly tested with 1.000.000 widgets and got 78 "inside" vs 95 "outside". With 125k widgets, however, both variants got 99.

Thread Thread
 
asyrialak profile image
Andrew Syriala

Stoked that you tried testing it out. It sounds like that test confirms its a bit of a premature optimization. Great tool in your toolbet if you ever need to render a millionish components at a time though.