Selector optimizations #334
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Selector Optimizations
This PR stabilizes Redux selector references to prevent unnecessary React re-renders, and extracts common selector patterns into shared utilities. The biggest example of this is we no longer re-render the pattern when a user changes the name of a shape.
When unrelated state changes occur, selectors that aggregate data were returning new array/object references even though the contents were identical. This triggered unnecessary downstream recomputation and React re-renders of the canvas.
We now use two memoization strategies for key selectors:
createDeepEqualSelector) - Skip computation when inputs are structurally equalcreateResultEqualSelector) - Return cached reference when output is structurally equalFor small arrays of IDs (
selectVisibleLayerIds,selectAllImageIds), the deep comparison cost is negligible. For larger vertex arrays, the comparison cost is still much lower than the downstream React/canvas re-render cost it prevents.