Skip to content

Some minor parser performance improvements for ts#16461

Merged
nicolo-ribaudo merged 25 commits intobabel:mainfrom
liuxingbaoyu:ts-parser-perf
Jul 17, 2024
Merged

Some minor parser performance improvements for ts#16461
nicolo-ribaudo merged 25 commits intobabel:mainfrom
liuxingbaoyu:ts-parser-perf

Conversation

@liuxingbaoyu
Copy link
Member

@liuxingbaoyu liuxingbaoyu commented May 1, 2024

Q                       A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

The performance improvement is only 1%-5%. :)

PS F:\babel\benchmark\babel-parser\real-case-ts> node .\bench.mjs
baseline 1 typescript parser.ts: 64.27 ops/sec ±1.36% (16ms)
current 1 typescript parser.ts: 66.94 ops/sec ±1.32% (15ms)
baseline 1 typescript parser.ts: 64.85 ops/sec ±1% (15ms)
current 1 typescript parser.ts: 67.24 ops/sec ±1.05% (15ms)
PS F:\babel\benchmark\babel-parser\real-case-ts> node .\bench.mjs
current 1 typescript parser.ts: 66.09 ops/sec ±1.45% (15ms)
baseline 1 typescript parser.ts: 63.51 ops/sec ±1.03% (16ms)
current 1 typescript parser.ts: 67.24 ops/sec ±0.82% (15ms)
baseline 1 typescript parser.ts: 64.26 ops/sec ±1.03% (16ms)

@liuxingbaoyu liuxingbaoyu added pkg: parser PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories labels May 1, 2024
@babel-bot
Copy link
Collaborator

babel-bot commented May 1, 2024

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/57365

@liuxingbaoyu liuxingbaoyu marked this pull request as draft May 1, 2024 20:11
return require("./babel-worker.cjs");
}
const worker = new JestWorker(require.resolve("./babel-worker.cjs"), {
enableWorkerThreads: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is 0.3s faster on my local machine. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately it will be 1s slower on mac. But anyway it is not really noticeable.

# enableWorkerThreads: true
$ make clean-lib && time yarn gulp build-babel
yarn gulp build-babel  11.68s user 1.15s system 427% cpu 3.001 total

# enableWorkerThreads: false
$ make clean-lib && time yarn gulp build-babel
yarn gulp build-babel  10.75s user 1.10s system 404% cpu 2.930 total

Comment on lines +31 to +42
copyFileSync(
require.resolve("@babel-baseline/parser"),
"./parser-baseline.cjs"
);
copyFileSync(
"../../../packages/babel-parser/lib/index.js",
"./parser-current.cjs"
);

const baseline = require("./parser-baseline.cjs");
const current = require("./parser-current.cjs");
Copy link
Member Author

Choose a reason for hiding this comment

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

I had to do this otherwise I would get unstable benchmarks for current and I don't understand why.
I suspect that might have something to do with it, but it's still weird. It shouldn't cause any effect.
image

@liuxingbaoyu liuxingbaoyu marked this pull request as ready for review May 1, 2024 20:57
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 19, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants