Skip to content

perf: use fast dashify function in parser.js#84

Merged
ai merged 1 commit into
postcss:mainfrom
hyperz111:fast-dashify
Dec 8, 2025
Merged

perf: use fast dashify function in parser.js#84
ai merged 1 commit into
postcss:mainfrom
hyperz111:fast-dashify

Conversation

@hyperz111

@hyperz111 hyperz111 commented Dec 7, 2025

Copy link
Copy Markdown
Contributor

Benchmark file:

import Benchmark from "benchmark";
import postcssJs from "postcss-js";
import postcssJs2 from "../postcss-js/index.mjs";

const suite = new Benchmark.Suite();
const style = {
  top: 10,
  '&:hover': {
    top: 5
  }
};

suite
        .add("postcss-js", () => postcssJs.parse(style))
        .add("postcss-js (fast dashify)", () => postcssJs2.parse(style))
        .on("cycle", function (event) {
                console.log(String(event.target));
        })
        .on("complete", function () {
                console.log("Fastest is " + this.filter("fastest").map("name"));
        })
        .run({ async: true });

Benchmark result:

postcss-js x 113,757 ops/sec ±0.58% (58 runs sampled)
postcss-js (fast dashify) x 178,389 ops/sec ±1.86% (60 runs sampled)

@hyperz111 hyperz111 changed the title chore: use fast dashify function in parser.js perf: use fast dashify function in parser.js Dec 7, 2025
@ai

ai commented Dec 8, 2025

Copy link
Copy Markdown
Member

Wow, great result.

@ai

ai commented Dec 8, 2025

Copy link
Copy Markdown
Member

I will merge and release it during this week

@hyperz111

Copy link
Copy Markdown
Contributor Author

@ai, can you try benchmark it yourself?

@ai ai merged commit e2654fb into postcss:main Dec 8, 2025
3 checks passed
@ai

ai commented Dec 8, 2025

Copy link
Copy Markdown
Member

My results:

postcss-js x 3,467,532 ops/sec ±3.65% (84 runs sampled)
postcss-js (fast dashify) x 3,670,041 ops/sec ±0.87% (88 runs sampled)
Fastest is postcss-js (fast dashify)

But hostly, you are using very simple input CSS. Proper benchmark should use more realistic example (try Bootstrap CSS as we do in PostCSS benchmark).

@ai

ai commented Dec 8, 2025

Copy link
Copy Markdown
Member

Thanks. Your fix was released in 5.0.2.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants