Skip to content

Speed up svg parsing and rendering - #170

Open
kunitoki wants to merge 2 commits into
mainfrom
dev/faster_svg
Open

Speed up svg parsing and rendering#170
kunitoki wants to merge 2 commits into
mainfrom
dev/faster_svg

Conversation

@kunitoki

Copy link
Copy Markdown
Owner

This pull request introduces significant optimizations and refactorings to the SVG and core text modules, primarily aimed at improving performance and maintainability. The most notable changes are the pre-resolution of gradient and filter references at parse time (avoiding repeated resolution during rendering), the introduction of a hash generator utility for efficient hashing, and the implementation of a fast CSS rule index for SVG parsing. Additionally, blend mode parsing has been simplified and made more robust, and some hot code paths have been optimized to reduce unnecessary allocations.

SVG Parsing and Rendering Optimizations:

  • Gradients and filters are now fully resolved at parse time, eliminating the need for repeated resolution during rendering. This involves traversing href chains for gradients and filters once and updating their lookup tables accordingly. (modules/yup_graphics/svg/yup_SVGParser.cpp [1] [2]
  • The resolveGradient and resolveFilter functions and their usages have been removed from the rendering code, as resolution is now handled during parsing. (modules/yup_graphics/drawables/yup_Drawable.cpp [1] [2] [3] [4]

CSS Rule Matching Improvements:

  • Introduced SVGCssRuleIndex, a new structure for fast lookup of CSS rules by tag, id, and class, and integrated it into the SVG CSS parser. This replaces brute-force matching and greatly improves stylesheet application performance. (modules/yup_graphics/svg/yup_SVGCssRule.h [1] modules/yup_graphics/svg/yup_SVGCssParser.h [2] modules/yup_graphics/svg/yup_SVGParser.cpp [3]

Hashing Infrastructure Improvements:

  • Extracted and documented a generic HashGenerator utility for use throughout the codebase, improving code reuse and maintainability. This is now used for hashing in both String and StringRef. (modules/yup_core/misc/yup_HashGenerator.h [1] modules/yup_core/text/yup_String.cpp [2] modules/yup_core/text/yup_StringRef.h [3] modules/yup_core/yup_core.h [4]
  • Added a hash function for StringRef in the default hash functions to enable its use as a key in hash maps. (modules/yup_core/containers/yup_HashMap.h [1] [2]

Blend Mode and Attribute Parsing Simplification:

  • Replaced long chains of conditional statements for blend mode parsing with a single utility function, making the code more concise and easier to maintain. (modules/yup_graphics/svg/yup_SVGParser.cpp [1] [2]
  • Optimized the SVG unit parsing function to avoid unnecessary string allocations, improving performance in a hot code path. (modules/yup_graphics/svg/yup_SVGParser.cpp modules/yup_graphics/svg/yup_SVGParser.cppL2060-R2014)

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.47095% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.73%. Comparing base (3167a0c) to head (ec4cd97).

Files with missing lines Patch % Lines
modules/yup_graphics/svg/yup_SVGCssParser.cpp 98.70% 3 Missing ⚠️
modules/yup_graphics/svg/yup_SVGParser.cpp 96.82% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #170      +/-   ##
==========================================
+ Coverage   80.58%   80.73%   +0.15%     
==========================================
  Files         777      779       +2     
  Lines       80278    80246      -32     
==========================================
+ Hits        64689    64786      +97     
+ Misses      15589    15460     -129     
Files with missing lines Coverage Δ
modules/yup_core/containers/yup_HashMap.h 98.36% <100.00%> (+<0.01%) ⬆️
modules/yup_core/misc/yup_HashGenerator.h 100.00% <100.00%> (ø)
modules/yup_core/text/yup_String.cpp 96.92% <ø> (-0.02%) ⬇️
modules/yup_core/text/yup_StringRef.h 86.66% <100.00%> (+0.95%) ⬆️
modules/yup_graphics/drawables/yup_Drawable.cpp 77.91% <100.00%> (-0.25%) ⬇️
modules/yup_graphics/svg/yup_SVGCssRule.h 100.00% <100.00%> (ø)
modules/yup_graphics/svg/yup_SVGParser.cpp 89.60% <96.82%> (+7.72%) ⬆️
modules/yup_graphics/svg/yup_SVGCssParser.cpp 98.62% <98.70%> (-1.01%) ⬇️

... and 5 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3167a0c...ec4cd97. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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