Skip to content

Fix alpha-value-notation performance with improved benchmark script#6864

Merged
romainmenke merged 9 commits intomainfrom
refactor-benchmark-rule-and-add-fast-abort-to-alpha-value-notation--inventive-possum-75c4dff57f
May 29, 2023
Merged

Fix alpha-value-notation performance with improved benchmark script#6864
romainmenke merged 9 commits intomainfrom
refactor-benchmark-rule-and-add-fast-abort-to-alpha-value-notation--inventive-possum-75c4dff57f

Conversation

@romainmenke
Copy link
Copy Markdown
Member

Which issue, if any, is this issue related to?

See : stylelint/css-parser#2

Is there anything in the PR that needs further explanation?

I was curious about performance and if there were any benchmark tools in place.

I found that the current benchmark script is just checking PostCSS performance, not rule performance in specific. I've refactored this script to separate the initial parsing phase and the plugin processing.

This gives a more relevant result to Stylelint plugins.

I also found that processing Bootstrap only once doesn't give meaningful results.
PostCSS is just too fast, the deviation too high and the actual duration per cycle with or without a code change isn't clear.

I found that duplicating the Bootstrap source 20 times gives a more useful output.

> node scripts/benchmark-rule.mjs alpha-value-notation ["number"]

Warnings: 0
Mean: 94.41161338888888 ms
Deviation: 12.21578916466738 ms
> node scripts/benchmark-rule.mjs alpha-value-notation ["number"]

Warnings: 0
Mean: 72.47793288888887 ms
Deviation: 6.865530836418062 ms

I have a M2 macbook air, which is possibly the worst machine to run benchmarks on.
So someone with a decent machine (no power saving cores, cooled cpu) should verify this work.


This change also adds some improvements to the first rule.
I just picked the first rule at random, not because I noticed anything wrong in terms of performance.

  • add a fast abort before any parsing
  • some minor code improvements

Changes like these do not take away the underlying issue as described in stylelint/css-parser#2

But I do think it is worthwhile to look into and apply trivial improvements like these.
Even with a different style parser it will be a good practice to add fast aborts before doing a deeper AST walk.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants