Загрузка видео...

Не удалось загрузить видео

На главную

❌ 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?

Похожие видео