𝗩𝗶𝗿𝘁𝘂𝗮𝗹 𝗗𝗢𝗠 𝗮𝗻𝗱 𝗗𝗶𝗳𝗳 𝗔𝗹𝗴𝗼𝗿𝗶𝘁𝗵𝗺

Real DOM is slow. Changing it makes your browser redraw the page. This takes time.

Virtual DOM is different. It is a light JavaScript object. It describes your UI structure.

Virtual DOM is not faster on its own. The real speed comes from the Diff algorithm.

The Diff algorithm finds the smallest change between the old and new UI. It only updates changed parts of the real DOM.

Efficiency = Virtual DOM + Diff Algorithm + Minimal DOM moves.

How the Diff algorithm works:

The double-ended Diff is a smart method. It uses four pointers to track the start and end of node lists.

It matches nodes from both ends. It moves nodes only if it finds a mismatch. This keeps your browser fast.

Source: https://dev.to/zhenghaoyang24/virtual-dom-and-diff-algorithm-497n