Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Not for merge?] Cache path parsing #2548

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gaearon
Copy link

@gaearon gaearon commented Nov 21, 2024

This function is showing up as taking ~20% of createViewInstance calls on my Android device which is a lot. We use react-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:

Screenshot 2024-11-21 at 00 40 30

This adds a cache, making it take ~3% of createViewInstance calls (7x improvement?):

Screenshot 2024-11-21 at 01 14 22

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant