Skip to content

Conversation

@SethFalco
Copy link
Member

@SethFalco SethFalco commented May 11, 2025

Minor performance improvement for the parsing of SVGs. Instead of using a regular expression, we assume we should trim the string.

  1. In the majority of cases, string#trim is faster than RegExp#test. ¹
  2. If the condition was true, we would call string#trim separately, but if we assume we should call string#trim, then the string is already prepped as we proceed.

¹ The only instance where RegExp#test is faster for our use-case is when a string has obscene amounts of whitespace on either end (50+ chars). In the overwhelming majority of cases that we encounter, the amount of whitespace found is about what you'd expect from formatted XML, which is so little that trimming works out faster.

Testing

I've checked and can confirm this has no impact on the final SVG for any of our regression tests.

@SethFalco SethFalco merged commit e645d71 into svg:main May 11, 2025
14 checks passed
@SethFalco SethFalco deleted the 💪(•ᴗ•💪) branch May 11, 2025 22:25
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