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
refactor(postcss-colormin): Improve caching. #771
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report
@@ Coverage Diff @@
## master #771 +/- ##
==========================================
+ Coverage 98.69% 98.72% +0.02%
==========================================
Files 110 116 +6
Lines 3061 3053 -8
==========================================
- Hits 3021 3014 -7
+ Misses 40 39 -1
Continue to review full report at Codecov.
|
Previously a cache was kept per property/value pair as well as the transformed value. This meant that otherwise identical values would result in a cache miss. Instead, we now cache at the value level and at the colour transform level, which should improve performance. This patch is also experimenting with a more declarative style using Ramda in order to do the caching, and some small quality of life fixes.
ludofischer
added a commit
that referenced
this pull request
May 18, 2021
fix(postcss-colormin): do not replace original value if shorter than conversion fix #1042 Also improve the minification in other cases, for example now emits hsla(0,0%,4%,1) instead of rgba(10,10,10,.1) feat(postcss-colormin): change to colord * round color values fix #819 * reduce dependencies perf(postcss-colormin): improve caching Fix #771 refactor(postcss-colormin): drop the generate script Finding the color name is hash lookup in any case. Cannot see how the extra work of loading a JSON file, parsing it, can improve performance.
ludofischer
added a commit
that referenced
this pull request
May 18, 2021
fix(postcss-colormin): do not replace original value if shorter than conversion fix #1042 Also improve the minification in other cases, for example now emits hsla(0,0%,4%,1) instead of rgba(10,10,10,.1) feat(postcss-colormin): change to colord * round color values fix #819 * reduce dependencies perf(postcss-colormin): improve caching Fix #771 refactor(postcss-colormin): drop the generate script Finding the color name is hash lookup in any case. Cannot see how the extra work of loading a JSON file, parsing it, can improve performance.
ludofischer
added a commit
that referenced
this pull request
May 18, 2021
fix(postcss-colormin): do not replace original value if shorter than conversion fix #1042 Also improve the minification in other cases, for example now emits hsla(0,0%,4%,1) instead of rgba(10,10,10,.1) feat(postcss-colormin): change to colord * round color values fix #819 * reduce dependencies perf(postcss-colormin): improve caching Fix #771 refactor(postcss-colormin): drop the generate script Finding the color name is hash lookup in any case. Cannot see how the extra work of loading a JSON file, parsing it, can improve performance.
ludofischer
added a commit
that referenced
this pull request
May 18, 2021
fix(postcss-colormin): do not replace original value if shorter than conversion fix #1042 Also improve the minification in other cases, for example now emits hsla(0,0%,4%,1) instead of rgba(10,10,10,.1) feat(postcss-colormin): change to colord * round color values fix #819 * reduce dependencies perf(postcss-colormin): improve caching Fix #771 refactor(postcss-colormin): drop the generate script Finding the color name is hash lookup in any case. Cannot see how the extra work of loading a JSON file, parsing it, can improve performance.
ludofischer
added a commit
that referenced
this pull request
May 18, 2021
* rework the colomin cache so use only one cache as in #771 (without using Ramda as in that PR). The cache key is now just the declaration value. Before there were two caches, one with a CSS `property|value` key and one that cached the single colors. * change the underlying library to [colord](https://github.com/omgovich/colord). Using `colord` comes with some trade-offs. On the plus side, it automatically rounds up up, which fixes an [open issue](#819) without additional work, reduces transitive dependencies from 4 to 0 (although I think the previous 4 are all maintained by the same people), is smaller and claims to be faster (haven't checked but I suspect css-value-parser is more the bottle neck than color conversion here). On the minus side, the `colord` parser is very lenient so it accepts invalid CSS colors (rgb with mixed percentages and numbers) which cssnano did not convert before, so I've added some checks to skip these values. Overall there are less lines of code. * get rid of the JSON file with precomputed CSS color names. I guess the idea was that the JSON file only contained color names that are shorter than the hex, but the color conversion libraries include all color names anyway to be able to parse, so in fact we ship the color names twice. I don't think the extra code for generating the file, plus loading the JSON is worth it to avoid a an extra length check. fix(postcss-colormin): do not replace original value with longer one fix #1042 feat(postcss-colormin): switch to colord * round color values fix #819 * reduce dependencies perf(postcss-colormin): improve caching Fix #771 refactor(postcss-colormin): drop the generate script
ludofischer
added a commit
that referenced
this pull request
May 18, 2021
* rework the colomin cache so use only one cache as in #771 (without using Ramda as in that PR). The cache key is now just the declaration value. Before there were two caches, one with a CSS `property|value` key and one that cached the single colors. * change the underlying library to [colord](https://github.com/omgovich/colord). Using `colord` comes with some trade-offs. On the plus side, it automatically rounds up up, which fixes an [open issue](#819) without additional work, reduces transitive dependencies from 4 to 0 (although I think the previous 4 are all maintained by the same people), is smaller and claims to be faster (haven't checked but I suspect css-value-parser is more the bottle neck than color conversion here). On the minus side, the `colord` parser is very lenient so it accepts invalid CSS colors (rgb with mixed percentages and numbers) which cssnano did not convert before, so I've added some checks to skip these values. Overall there are less lines of code. * get rid of the JSON file with precomputed CSS color names. I guess the idea was that the JSON file only contained color names that are shorter than the hex, but the color conversion libraries include all color names anyway to be able to parse, so in fact we ship the color names twice. I don't think the extra code for generating the file, plus loading the JSON is worth it to avoid a an extra length check. fix(postcss-colormin): do not replace original value with longer one fix #1042 feat(postcss-colormin): switch to colord * round color values fix #819 * reduce dependencies perf(postcss-colormin): improve caching Fix #771 refactor(postcss-colormin): drop the generate script
ludofischer
added a commit
that referenced
this pull request
May 18, 2021
* rework the colomin cache so use only one cache as in #771 (without using Ramda as in that PR). The cache key is now just the declaration value. Before there were two caches, one with a CSS `property|value` key and one that cached the single colors. * change the underlying library to [colord](https://github.com/omgovich/colord). Using `colord` comes with some trade-offs. On the plus side, it automatically rounds up up, which fixes an [open issue](#819) without additional work, reduces transitive dependencies from 5 to 0 (although I think the previous 4 are all maintained by the same people), is smaller and claims to be faster (haven't checked but I suspect css-value-parser is more the bottle neck than color conversion here). On the minus side, the `colord` parser is very lenient so it accepts invalid CSS colors (rgb with mixed percentages and numbers) which cssnano did not convert before, so I've added some checks to skip these values. Overall there are less lines of code. * get rid of the JSON file with precomputed CSS color names. I guess the idea was that the JSON file only contained color names that are shorter than the hex, but the color conversion libraries include all color names anyway to be able to parse, so in fact we ship the color names twice. I don't think the extra code for generating the file, plus loading the JSON is worth it to avoid a an extra length check. fix(postcss-colormin): do not replace original value with longer one fix #1042 feat(postcss-colormin): switch to colord * round color values fix #819 * reduce dependencies perf(postcss-colormin): improve caching Fix #771 refactor(postcss-colormin): drop the generate script
ludofischer
added a commit
that referenced
this pull request
May 18, 2021
* ensure that the replacement color values are shorter than the origina. Previously, the plugin returned the converted value without checking whether it was shorter than the original, we now ensure we always return the shortest color value * rework the colomin cache so use only one cache as in #771 (without using Ramda as in that PR). The cache key is now just the declaration value. Before there were two caches, one with a CSS `property|value` key and one that cached the single colors. * change the underlying library to [colord](https://github.com/omgovich/colord). Using `colord` comes with some trade-offs. On the plus side, it automatically rounds up up, which fixes an [open issue](#819) without additional work, reduces transitive dependencies from 5 to 0 (although I think the previous 4 are all maintained by the same people), is smaller and claims to be faster (haven't checked but I suspect css-value-parser is more the bottle neck than color conversion here). On the minus side, the `colord` parser is very lenient so it accepts invalid CSS colors (rgb with mixed percentages and numbers) which cssnano did not convert before, so I've added some checks to skip these values. Overall there are less lines of code. * get rid of the JSON file with precomputed CSS color names. I guess the idea was that the JSON file only contained color names that are shorter than the hex, but the color conversion libraries include all color names anyway to be able to parse, so in fact we ship the color names twice. I don't think the extra code for generating the file, plus loading the JSON is worth it to avoid a an extra length check. fix(postcss-colormin): do not replace original value with longer one fix #1042 feat(postcss-colormin): switch to colord * round color values fix #819 * reduce dependencies perf(postcss-colormin): improve caching Fix #771 refactor(postcss-colormin): drop the generate script
ludofischer
added a commit
that referenced
this pull request
May 18, 2021
* ensure that the replacement color values are shorter than the original. Previously, the plugin returned the converted value without checking whether it was shorter than the original, we now ensure we always return the shortest color value * rework the colomin cache so use only one cache as in #771 (without using Ramda as in that PR). The cache key is now just the declaration value. Before there were two caches, one with a CSS `property|value` key and one that cached the single colors. * change the underlying library to [colord](https://github.com/omgovich/colord). Using `colord` comes with some trade-offs. On the plus side, it automatically rounds up up, which fixes an [open issue](#819) without additional work, reduces transitive dependencies from 5 to 0 (although I think the previous 4 are all maintained by the same people), is smaller and claims to be faster (haven't checked but I suspect css-value-parser is more the bottle neck than color conversion here). On the minus side, the `colord` parser is very lenient so it accepts invalid CSS colors (rgb with mixed percentages and numbers) which cssnano did not convert before, so I've added some checks to skip these values. Overall there are less lines of code. * get rid of the JSON file with precomputed CSS color names. I guess the idea was that the JSON file only contained color names that are shorter than the hex, but the color conversion libraries include all color names anyway to be able to parse, so in fact we ship the color names twice. I don't think the extra code for generating the file, plus loading the JSON is worth it to avoid a an extra length check. fix(postcss-colormin): do not replace original value with longer one fix #1042 feat(postcss-colormin): switch to colord * round color values fix #819 * reduce dependencies perf(postcss-colormin): improve caching Fix #771 refactor(postcss-colormin): drop the generate script
ludofischer
added a commit
that referenced
this pull request
May 19, 2021
…1107) * ensure that the replacement color values are shorter than the original. Previously, the plugin returned the converted value without checking whether it was shorter than the original, we now ensure we always return the shortest color value * rework the colomin cache so use only one cache as in #771 (without using Ramda as in that PR). The cache key is now just the declaration value. Before there were two caches, one with a CSS `property|value` key and one that cached the single colors. * change the underlying library to [colord](https://github.com/omgovich/colord). Using `colord` comes with some trade-offs. On the plus side, it automatically rounds up up, which fixes an [open issue](#819) without additional work, reduces transitive dependencies from 5 to 0 (although I think the previous 4 are all maintained by the same people), is smaller and claims to be faster (haven't checked but I suspect css-value-parser is more the bottle neck than color conversion here). On the minus side, the `colord` parser is very lenient so it accepts invalid CSS colors (rgb with mixed percentages and numbers) which cssnano did not convert before, so I've added some checks to skip these values. Overall there are less lines of code. * get rid of the JSON file with precomputed CSS color names. I guess the idea was that the JSON file only contained color names that are shorter than the hex, but the color conversion libraries include all color names anyway to be able to parse, so in fact we ship the color names twice. I don't think the extra code for generating the file, plus loading the JSON is worth it to avoid a an extra length check. fix(postcss-colormin): do not replace original value with longer one fix #1042 feat(postcss-colormin): switch to colord * round color values fix #819 * reduce dependencies perf(postcss-colormin): improve caching Fix #771 refactor(postcss-colormin): drop the generate script
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously a cache was kept per property/value pair as well as the transformed value. This meant that otherwise identical values would result in a cache miss. Instead, we now cache at the value level and at the colour transform level, which should improve performance.
This patch is also experimenting with a more declarative style using Ramda in order to do the caching, and some small quality of life fixes.
@evilebottnawi What do you think? Should we continue with this style?