react diff minimalist version

  Why react so fast it  ?

  Because react with a virtual DOM;

 

  But each time the virtual DOM DOM does not turn real performance is also a waste it ?

  nice ,? so the key point here Diff algorithm, to compare the old and new DOM tree, then go to the real update the DOM patch ;

 

  The match is also not a waste of time ?

  Under normal circumstances, the time complexity of the algorithm is to compare two structural differences tree is O (N ^ 3), the efficiency is clearly unacceptable.

  DOM react by summarizing actual usage scenario presents two scenarios in practice the vast majority of the assumptions, based on these two assumptions, React to achieve a relatively complete two virtual DOM tree within the (N) time complexity O .

  Two hypotheses are:

    (1) If the two elements of different types, they will generate two different trees;

    (2) set the key attribute in the list of elements, with the key element in a plurality of times corresponding to the identifier;

 

  Performance Optimization facing what can we do ?

    1, using the production version of the library;

     2, to avoid unnecessary component rendering;

     3, using the Key;  

 

 

  

  

Guess you like

Origin www.cnblogs.com/webcabana/p/11236227.html