正在加载视频...

视频加载失败

❌ Avoid increasing time complexity by having non-normalized state variables in React . ✅ Instead normalize the structure of the state variables to reduce time complexity.

177,601 次观看 • 2 年前 •via X (Twitter)

10 条评论

George Moller 的头像
George Moller2 年前

Hey there 👋 Friendly reminder that I have more than 100 infographics and video animations just like this one. Check them out ↓

George Moller 的头像
George Moller2 年前

Hey there 👋 Friendly reminder that I have more than 100 infographics and video animations just like this one. Check them out ↓

Hammad Ahmad 的头像
Hammad Ahmad2 年前

noice , ok what if we get data from an Api call , then , we first loop all the array of object to store ids and entities, then we will again loop over the data , and then time completely will be O(n2) . i mean really? correct if i am wrong 😑 .

George Moller 的头像
George Moller2 年前

@ch_hadi0 Data should already come normalized from the API backend

mvrlin 的头像
mvrlin2 年前

What’s the point of having ids and entities? Now you have O(n^2) space complexity. Just use plain object or even better Map.

Pavel Romanov 的头像
Pavel Romanov2 年前

I’ve seen such things in a wild and sometimes it can really boost your performance! The only thing I would change is to convert “users” to the Map. I’ve found it really useful lately

Vojtěch Jedlička 的头像
Vojtěch Jedlička2 年前

This doesn't make much sense to me. 1. Map is designed to do exactly this. 2. There is no noticeable performance difference for smaller than huge arrays and those should be paginated anyways.

George Moller 的头像
George Moller2 年前

Not for smaller arrays, but try measuring the performance of the find method against the map when you have thousand of entries/records and you'll see a notable difference.

ricklove 的头像
ricklove2 年前

No, don’t introduce complexity. Lookups should only be used inside an algorithm with a loop. Code review failed.

RadicalRabbit 的头像
RadicalRabbit2 年前

Why is a seperate array of just ids needed?

相关视频