|
|
|
|
|
by codedokode
398 days ago
|
|
The react's algorithm of detecting changes is based on rebuilding a Virtual DOM tree (i.e. recalculating all components) and comparing that tree to the previous one. It is done, as I understand, every time someone calls update() or similar method on a component. So React won't cause performance issues only if you have few model variables or manually optimize the code by using immutable data structures (which have their own performance issues) and pure components. For comparison, Vue detects changing by wrapping all model variables with proxies and linking them to UI components that use them. This has an advantage of not having to recalculate everything and disadvantage of having an overhead for using proxies and creating a dependency graph. Also, having to deal with proxies adds more pain for the programmer. |
|
- React doesn't really distinguish between DOM components and your own components in how it evaluates. It's all part of the same "VDOM" tree. Creating and updating HTML tags doesn't flow differently from updating the props on your own components.
- React does sparse updates, starting at the topmost component(s) whose state changed. Frequently this is just one widget or a button. Full tree re-evaluation is rare.
- If a component has the _exact_ same `children` prop as before (`===`), as is often the case with e.g. context providers, because it was assigned by a parent, then React will skip re-rendering the children entirely with no effort from the developer.
- If a component is memoized with `memo(...)`, then a re-render will be stopped if it has the same props as before. This means even if your state lives high up in the tree, judicious use of memo can make it zippy af.
TLDR: If your react app is re-calculating the entire tree, you suck at react and you never bothered to learn it. Skill issue, git gud, etc. You're welcome.