This adds a new API, createSelector, that lets you define optimizable selectors. These selectors can be optimized using the unstable_observedBits React context API. This optimization strategy assumes that selectors, not consumers, are the basic abstraction for composability; since selectors can be re-used between consumers optimizing at the selector level is inherently more powerful.
These selectors are optimized using a heuristic based on the reference count for a given selector; the first 29 selectors used in mounted consumers are always optimized. After that, they get queued up for optimization. Once an optimized selector can be de-optimized (all the consumers using it unmount) it frees up a slot, and the queued selector with the highest reference count is optimized.
cc @gaearon
TODO
[ ] Write some tests
[ ] Ensure queued selectors are removed once their reference count hits 0
[ ] Use a better data structure for optimizationQueue
[ ] Determine next selector to optimize based on reference count
[ ] Dont increase reference count in optimizeSelector
[ ] Should it avoid optimizing selectors when they are used alongside unoptimzed selectors? Those unoptimized seletors will force a de-opt anyways, so maybe save the slots?
This adds a new API,
createSelector
, that lets you define optimizable selectors. These selectors can be optimized using theunstable_observedBits
React context API. This optimization strategy assumes that selectors, not consumers, are the basic abstraction for composability; since selectors can be re-used between consumers optimizing at the selector level is inherently more powerful.These selectors are optimized using a heuristic based on the reference count for a given selector; the first 29 selectors used in mounted consumers are always optimized. After that, they get queued up for optimization. Once an optimized selector can be de-optimized (all the consumers using it unmount) it frees up a slot, and the queued selector with the highest reference count is optimized.
cc @gaearon
TODO
optimizationQueue
optimizeSelector