r/javascript • • Mar 20 '22

A real-world example of Improving JavaScript performance

https://www.the-koi.com/projects/an-practical-example-on-improving-javascript-performance/
51 Upvotes

11 comments sorted by

12

u/Nullberri Mar 20 '22 edited Mar 21 '22

Seems like most of the article was "I used the wrong tool for the job and didn't understand my needs very well"

was there a way to design your setup without needing a circular reference? What if you really did need to deep clone because the values get modified later and need fresh copies? How would you have resolved the design choice?

What drove your design decision to use deepclone in the first place? was their originally a need that then dropped later?

1

u/No-Onion-8207 Mar 21 '22

Hi thanks for your great reply. Unfortunately I need this circular reference for some other features, but I did not need to deepClone my Object here. I also thought about that, but if I needed to do fresh copies I would have to refactor this features that relied on that reference or manually clone the object without its circular structure.

Thatโ€™s why I wanted to write this article because I always preferred deep copy over shallow copy and did not thought about the memory and performance issues that could come from this simple call.

2

u/iamnearafan Mar 29 '22

I know it's not applicable to all use cases but I recently used Redis cache to improve the speed of my site's time to first byte by about 95%. If it's useful I can share it, but you can have an essentially real time Redis cache that can help improve backend Javascript performance massively. Obviously uses a lot of memory sometimes though.

1

u/No-Onion-8207 Mar 29 '22

That sounds amazing! ๐Ÿ˜ I will try it also for my project ๐Ÿ˜ does redis also work for Frontend js?

1

u/iamnearafan Mar 29 '22

You'd have to use a server side rendered website for this to work. If you're using a framework, it's harder. The idea is that on the server side, you often do a lot of processing. With Redis, you can save all the output of the process and skip the processing altogether if a cached version exists. I wrote about it here if you're interested.

15

u/realPubkey Mar 20 '22

Tldr; use flat clone instead of deep clone

11

u/Nullberri Mar 21 '22

It's maybe sillier than that.

use deepclone when you actually need it, if you don't need a deep copy you can use a shallow clone.

2

u/lamb_pudding Mar 20 '22

Decent article but that site has too many ads.

1

u/No-Onion-8207 Mar 21 '22

Thank you for your feedback, Iโ€™m currently A/B testing googles auto ads feature and I also think that it is putting to much ads on my site.

3

u/Deren16 Mar 20 '22

Useful, thanks for posting!

2

u/sohang-3112 Mar 21 '22

console.time is interesting - didn't know about it!