-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
Skip running color match regex, if not required #186
Conversation
Probably a first time in this repo. |
I think package-lock.json needs to be updated as well. |
Sorry forgot about it. Updated. |
@HarelM, Can you please take a look. |
I stumbled across this change and it intrigued me. https://jsbench.me/mdli7ehoen/1 It seems that better performance boost would be if you simply put the regexp declarations in a higher scope. But in any case, I don't think the current color parsing performance is a big problem that critically needs to be optimized. |
Ahh interesting! :-) |
I had tested moving regex to higher scope and it did no showed much difference before making this change. Here is updated test with Regex moved to setup Testing for Hex and RGB Testing for just Hex Intent of the original test(https://jsbench.me/4blhzc953l/1) was to see if adding a cheap startswith validation will be much faster then a full regex match without any additional code. In Bing maps road style we have 158 #hex and 201 HSL. Maplibre default style has 94 #hex, 79 RGB and 11 HSL. Testing with mixed color format, dilutes the test and does not test the change that was intended. Like having hex color will force test to also run its regex. Intend was to simply have a cheap way to test the color before running regex. |
I compared the entire parsing functions (had to minify code as it is at the jsbench limits): https://jsbench.me/mdli7ehoen/2 The results made me think why my earlier test would suggest the opposite. And so I noticed that I added a So yes, I was wrong and this change indeed improves color parsing performance. Sorry for claiming otherwise 😔 As a final note, I would like to add that I disagree with the statement that testing with mixed formats dilutes the test, in my opinion it is more valuable because it verifies the additional cost for the hex/rgb() paths, instead of focusing only on the benefits for the hsl() path. |
Color Parsing is in a critial hot path and is executed multiple times while style parsing. This PR brings in a small optimization.
Before running a expensive color match regex run a cheap validation. Tests shows a 98% improvement if color is specified in HSL format. There will be some improvement when color is specified in rgb format as well.
Test: https://jsbench.me/4blhzc953l/1
Launch Checklist
CHANGELOG.md
under the## main
section.