-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Add support for color string in JSON array format #189
Conversation
src/util/parse_color.ts
Outdated
clamp(+b / 255, 0, 1), | ||
clamp(isNaN(a) ? 1 : +a, 0, 1)]; | ||
} | ||
} catch(ex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding previously was that try/catch was slower. But looks like modern browsers have improved and now I don't see any perf issue with using try/catch (tested on Edge/Chrome/Firefox). Adding try/catch here allow to catch all invalid JSON string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think try-catch is slower compared to ifs, in case you go through the catch part of the try-catch, at least is what I was taught long time ago... :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if code goes inside catch then its quite slow. But for any production style, it should never go into catch block as it will be a invalid color and thus production code does not suffer from any performance degradation in this case. Overhead of adding various checks to validate JSON format will eat away any performance benefits apart from adding code complications.
Can you post benchmark results against regular color parsing ( |
Here are the results using the code used in this PR from my home machine. RGB, RGBA and HSL is 50-65% slower then JSON array (depending on machine). |
As per discussion in #187, holding on to this PR (Moving to draft). Will first impliment color caching which will help improve color parsing by about 50%. If there is still need to further improve, will come back to this PR. |
@pramilk I'm closing this PR for now to reduce clutter. |
Please see discussion #187 for details
Launch Checklist
CHANGELOG.md
under the## main
section.