You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When rendering SVG files containing large amount of text, I noticed there are frequent file I/O operations for reading font files, which significantly impacts performance. This becomes more noticeable as the number of text in the SVG increases.
Reproduction
I created a minimal reproduction case that demonstrates the issue:
On my MBP M2Pro, the result is as follows, the buildResvg stage takes 303ms.
When the amount of text is 3000, the buildResvg stage takes 1500ms.
Investigation
Through system-level logging, I observed that the program repeatedly reads font files from disk during the rendering process. This appears to be happening because the font files are being accessed multiple times rather than being loaded into memory once.
I believe this might be related to how the underlying dependencies (resvg/fontdb) handle font loading, rather than an issue with resvg-js itself.
Impact
Significant performance degradation when rendering SVGs with multiple text elements
Unnecessary I/O overhead
Potential system resource contention in high-load scenarios
Potential Solution
I've submitted a PR (#366 ) that adds a preloadFonts option to load font files into memory at initialization to avoid disk io. While this doesn't address the root cause in the underlying libraries, it provides a practical workaround for resvg-js users experiencing performance issues with text-heavy SVGs.
constresvg=newResvg(svgWithLargeAmountOfText,{font: {fontFiles: [// ttf font file download from https://www.alibabafonts.com/#/font"/Users/xx/AlibabaPuHuiTi-2-35-Thin.ttf",],loadSystemFonts: false,preloadFonts: false,},background: "#ffffff",});
After applying the optimization, the result is as follows, the buildResvg stage takes only 8ms(from 303ms).
When the amount of text is 3000, the buildResvg stage takes 15ms(from 1500ms, 100x faster 😄).
Would love to hear your thoughts on:
Whether this is a known issue in the underlying dependencies
If this local optimization makes sense as an interim solution
If you'd prefer to handle this differently
Let me know if you need any additional information or benchmarks.
The text was updated successfully, but these errors were encountered:
Issue Description
When rendering SVG files containing large amount of text, I noticed there are frequent file I/O operations for reading font files, which significantly impacts performance. This becomes more noticeable as the number of text in the SVG increases.
Reproduction
I created a minimal reproduction case that demonstrates the issue:
On my MBP M2Pro, the result is as follows, the buildResvg stage takes 303ms.
When the amount of text is 3000, the buildResvg stage takes 1500ms.
Investigation
Through system-level logging, I observed that the program repeatedly reads font files from disk during the rendering process. This appears to be happening because the font files are being accessed multiple times rather than being loaded into memory once.
I believe this might be related to how the underlying dependencies (resvg/fontdb) handle font loading, rather than an issue with resvg-js itself.
Impact
Potential Solution
I've submitted a PR (#366 ) that adds a
preloadFonts
option to load font files into memory at initialization to avoid disk io. While this doesn't address the root cause in the underlying libraries, it provides a practical workaround for resvg-js users experiencing performance issues with text-heavy SVGs.After applying the optimization, the result is as follows, the buildResvg stage takes only 8ms(from 303ms).
When the amount of text is 3000, the buildResvg stage takes 15ms(from 1500ms, 100x faster 😄).
Would love to hear your thoughts on:
Let me know if you need any additional information or benchmarks.
The text was updated successfully, but these errors were encountered: