Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to std::unordered_map for shadow and Yoga nodes (#10543)
* Switch to std::unordered_map for shadow and Yoga nodes We previously used std::map in ShadowNodeRegistry and NativeUIManager for the storage of shadow nodes (former) and Yoga nodes and context (latter), which has O(log(n)) complexity for insertion, removal, and access. The main reason for using std::map over std::unordered_map is when you require ordered enumeration of keys, which none of these maps require. - Shadow nodes are only enumerated when destroying the UIManagerModule to cleanup by calling `DropView` on the shadow node. Tag indices themselves do not specify much besides creation order, and while children generally have smaller indices than parents in very simple cases, this is not always the case (consider a component that adds a child after some state change, the child index will be larger than its parent). Thus, there is no semantics coupled to the tag value, and no point in enforcing in-order enumeration. - Yoga nodes are only enumerated for applying Yoga results to views, and the same logic above applies, there is no semantics to tag order, thus no point in enforcing in-order enumeration. #10422 actually changes this behavior to recursively apply Yoga results to children in depth-first order, so there will be no remaining enumerations of Yoga nodes. - Yoga context values are never enumerated, so an ordered map is not required. There are two motivations for switching the map type: 1. Effects of logarithmic insertion, removal, and access become noticeable in apps with many nodes, like Messenger. 2. We are experimenting with ViewFlattening in the Paper UIManager for RN Windows, which require many more accesses of the ShadowNodeRegistry than are required today. * Change files
- Loading branch information