In an app I'm building, I use SVGs in certain list items. The SVGs are custom status icons and thus are pretty simple. They contain trivial path and circle elements, have one color without any fancy gradients.
The list feels a bit janky though, especially on my crappiest Android test device. My intuition was already when I added the SVGs that this might happen. Android is not the most performant with vector graphics, especially when using react-native-svg.
I did some profiling with the Flipper mobile app debugging tool. My gut feeling was confirmed. The component which is the most prominently visible in the flame graph is the SVG, being almost ten times slower to render than the text components.
Performance of the SVG component |
Since the SVGs are so simple, the solution to this performance problem is to convert the set to a font. We use a ton of icon fonts, and they are almost as fast to render as "normal" text.
I used IcoMoon for the conversion. As expected, IcoMoon complained about the SVGs having some incorrect elements that cant convert on the first try. Fortunately, the site has high-grade documentation on how to fix that, awesome! After some Inkscape magic, I got the icon font files out from IcoMoon.
Converting elements to paths made the conversion to font possible |
Finished font |
What was left is to try out the font. Adding a new icon font was easy, and in no time, I was back profiling. The new flame graphs showed about 4x performance improvement. The lag in the list was gone. Not bad for a half days job!
Comments
Post a Comment