[Not for merge?] Cache path parsing #2548
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.
This function is showing up as taking ~20% of
createViewInstance
calls on my Android device which is a lot. We usereact-native-svg
for rendering icons — which may be not a great fit but unfortunately we haven't taken a close look at the runtime characteristics when we started using it. This library seems better-suited to dynamic stuff whereas we're just rendering the same icons over and over. Here's a trace showing this function being a hot spot:This adds a cache, making it take ~3% of
createViewInstance
calls (7x improvement?):Still not ideal but I'll take it! This "fix" is a patch I'm planning to apply as we're trying to fix different causes of slowness on Android. Since in our case, there's only a limited number of icons, it's appropriate to cache these paths forever.
I don't think it makes sense to merge this PR since keeping it forever is not the right tradeoff for many people. Something like LRU might not be bad but is still unpredictable, and something with an explicit API might not be in SVG's spirit. So maybe this doesn't make sense to merge in any way — but I wanted to start a discussion. Maybe another library can be recommended more explicitly for cases like ours — I doubt it's obvious to many users that paths get parsed over and over.
Thanks!