DOM Diffing

Whenever there is a change in the state of the UI elements, a new virtual DOM is created. Then the new virtual DOM and the previous virtual DOM are compared with each other. This comparing is called DOM diffing.

The intention is to perform minimal operations on the real DOM, hence after diffing, the best way to update the real DOM is calculated, leading to an efficient update of the UI.

The following image shows the diffing process:

DOM Diffing

The image shows that the update on the real DOM is postponed as further as possible. The red node represents state change; then, the changes are calculated through DOM diffing, and finally, the new virtual DOM is batch updated to the real DOM.

Explain DOM Diffing

DOM Diffing or Document Object Model Diffing is the concept of comparing the DOMs before and after the modification and ensuring efficient updates. Before understanding DOM Diffing deeply, we should know what DOM is and what is its purpose.

Similar Reads

Prerequisites:

DOM React JS Virtual DOM React JS Reconciliation...

What is a DOM ? :

In a formal sense, a DOM is an application programming interface (API) for documents. DOM defines a logical structure for a document and helps developers to access and manipulate a document. It very closely resembles the document models. For example, consider the following HTML list....

DOM Diffing :

Whenever there is a change in the state of the UI elements, a new virtual DOM is created. Then the new virtual DOM and the previous virtual DOM are compared with each other. This comparing is called DOM diffing....

Conclusion:

Updating UI is very expensive; updating the real DOM in batches improves the overall performance of repainting the UI....

Contact Us