I don't really understand why virtual DOM is faster.

Asked 1 years ago, Updated 1 years ago, 87 views

I heard that using virtual DOM is faster than working with real DOM. I don't really understand why it gets faster.

When I hear the explanation that the difference is changed by comparing before and after the change, I think I will understand.
Do you mean to use the browser's ability to re-render parts of the DOM, not the whole DOM?

I would appreciate it if you could tell me what kind of javascript functions are executed in such cases.

Thank you for your cooperation.

javascript reactjs dom

2022-09-29 22:48

1 Answers

If you look at it, I think the source of this word is around the article Why is real DOM so slow

Using a virtual DOM does not make it faster than using an optimized JavaScript to operate a real DOM.

In the case of using a virtual DOM, the meaning of the word is high speed because only the difference is rendered without the care of the front implementer.If not used, the implementer needs to think about the difference between Dom and code, but it is difficult to write the best code.

For more information, I think it's best to read the article, but it's not accurate, but it's as follows:

Rendering is the heaviest process on the browser display, with the following actions:

  • Create a rendering tree with style assignments
  • Calculating layout on rendering tree
  • And paint the screen based on the layout results

So if you want to speed up your browser's display, reducing unnecessary rendering is the most effective way to achieve this by using "virtual DOM" and applying only the necessary changes to the actual DOM using the difference algorithm.

JavaScript is pretty fast, so it doesn't take much time to create a virtual DOM.In addition, React.js was the first to use "virtual DOM" and React.js worked hard on "virtual DOM" to perform high-speed processing, so "virtual DOM" was evaluated as fast.However, the browser side is also trying to speed up the actual DOM, so it is no longer as different as it was now.


2022-09-29 22:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.