perf: skip and cache color computations in TouchableRipple and Chip (#4946) - #5113
Open
ErfanBagheri404 wants to merge 1 commit into
Open
perf: skip and cache color computations in TouchableRipple and Chip (#4946)#5113ErfanBagheri404 wants to merge 1 commit into
ErfanBagheri404 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #4946
Changes
TouchableRipple -
hoverColoris a web-only style (used only instate.hovered), but thecolor(calculatedRippleColor).fade(0.5).rgb().string()chain ran on every render of every TouchableRipple child, including on iOS/Android where the result was never read. Wrapped inReact.useMemogated byPlatform.OS === 'web', so native skips the entire computation. TouchableRipple wraps buttons, list items, etc - this is one of the most-rendered components in the library.Chip helpers -
color(selectedColor).alpha(0.29).rgb().string()ran per Chip per render when a custom selection color was set. Replaced with a module-levelMapcache (getSelectedColorBorder) keyed by the input color string, so the parse+alpha+stringify chain runs once per unique color and is reused on subsequent renders.Benchmark (color@3.1.2)
.alpha(0.29).rgb().string().fade(0.5).rgb().string().isLight()For a 30-item settings list where every row is wrapped in TouchableRipple: ~61 µs per parent re-render was spent computing
hoverColoron native - pure dead work. After this change: 0.What was already done upstream
The issue's original file list (Divider, List.Item, Appbar.Action, TextInput helpers) was stale - those sites were already fixed in recent commits. Only TouchableRipple and Chip remained.
Verification
jest- Chip: 27/27, TouchableRipple: 5/5tsc -b- cleaneslint- clean