Skip to content
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

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

Conversation

romainmenke
Copy link
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.

@changeset-bot
Copy link

changeset-bot bot commented May 27, 2023

🦋 Changeset detected

Latest commit: d9c3499

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
stylelint Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ybiquitous ybiquitous changed the title refactor benchmark-rule.mjs and add a fast abort to alpha-value-notation Fix alpha-value-notation performance with improved benchmark script May 27, 2023
Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romainmenke Thanks for the pull request. This change definitely makes sense. 👍🏼

Let's add this to the changelog to easily track it.


FYI, here is my benchmark on M1 MacBook Pro and Node.js v20.2.0:

Before:

Warnings: 0
Mean: 105.49801229411766 ms
Deviation: 14.985993295535048 ms

After:

Warnings: 0
Mean: 84.28338958823528 ms
Deviation: 8.832248644160641 ms

lib/rules/alpha-value-notation/index.js Outdated Show resolved Hide resolved
romainmenke and others added 5 commits May 27, 2023 15:46
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
…ue-notation--inventive-possum-75c4dff57f' of https://github.com/stylelint/stylelint into refactor-benchmark-rule-and-add-fast-abort-to-alpha-value-notation--inventive-possum-75c4dff57f
Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. LGTM! 👍🏼

@romainmenke romainmenke merged commit 2c7ae85 into main May 29, 2023
14 checks passed
@romainmenke romainmenke deleted the refactor-benchmark-rule-and-add-fast-abort-to-alpha-value-notation--inventive-possum-75c4dff57f branch May 29, 2023 09:14
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.

None yet

3 participants