-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Some minor parser performance improvements for ts #16461
Open
liuxingbaoyu
wants to merge
17
commits into
babel:main
Choose a base branch
from
liuxingbaoyu:ts-parser-perf
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
dba5391
chore
liuxingbaoyu 3fd35b3
chore
liuxingbaoyu f158551
chore
liuxingbaoyu 504c66c
chore
liuxingbaoyu 3c40960
dep
liuxingbaoyu 9cde6c3
plugins opt
liuxingbaoyu 0f1eb79
chore
liuxingbaoyu b7fd32e
fix
liuxingbaoyu 3468a9f
clean
liuxingbaoyu b268d8b
yarn dedupe
liuxingbaoyu 520b5bb
fix
liuxingbaoyu 2dbadd4
fix rebase
liuxingbaoyu 9379a6a
fix tests
liuxingbaoyu 537a6c8
Merge branch 'main' into ts-parser-perf
liuxingbaoyu c12f0ec
lint
liuxingbaoyu 7731bf1
chore
liuxingbaoyu 8cf4f99
Merge branch 'main' into ts-parser-perf
liuxingbaoyu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import Benchmark from "benchmark"; | ||
import baseline from "@babel-baseline/parser"; | ||
import current from "@babel/parser"; | ||
import { report } from "../../util.mjs"; | ||
import { readFileSync } from "fs"; | ||
import { copyFileSync, readFileSync, rmSync } from "fs"; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { commonJS } from "$repo-utils"; | ||
import { Benchmark } from "../../util.mjs"; | ||
|
||
const suite = new Benchmark.Suite(); | ||
const { require } = commonJS(import.meta.url); | ||
|
||
const benchmark = new Benchmark(); | ||
|
||
function createInput(length) { | ||
return readFileSync(new URL("ts-parser.txt", import.meta.url), { | ||
|
@@ -19,7 +20,7 @@ const inputs = [1].map(length => ({ | |
|
||
function benchCases(name, implementation, options) { | ||
for (const input of inputs) { | ||
suite.add(`${name} ${input.tag} typescript parser.ts`, () => { | ||
benchmark.add(`${name} ${input.tag} typescript parser.ts`, () => { | ||
implementation(input.body, { | ||
sourceType: "module", | ||
plugins: ["typescript"], | ||
|
@@ -28,10 +29,25 @@ function benchCases(name, implementation, options) { | |
}); | ||
} | ||
} | ||
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"); | ||
|
||
Comment on lines
+32
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
benchCases("current", current.parse); | ||
benchCases("baseline", baseline.parse); | ||
benchCases("current", current.parse); | ||
benchCases("baseline", baseline.parse); | ||
|
||
suite.on("cycle", report).run(); | ||
benchmark.suite.on("complete", () => { | ||
rmSync("./parser-current.cjs"); | ||
rmSync("./parser-baseline.cjs"); | ||
}); | ||
benchmark.run(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,13 @@ | |
"private": true, | ||
"type": "module", | ||
"devDependencies": { | ||
"@babel-baseline/core": "npm:@babel/core@7.23.2", | ||
"@babel-baseline/generator": "npm:@babel/generator@7.23.0", | ||
"@babel-baseline/helper-compilation-targets": "npm:@babel/helper-compilation-targets@7.22.15", | ||
"@babel-baseline/core": "npm:@babel/core@7.24.4", | ||
"@babel-baseline/generator": "npm:@babel/generator@7.24.4", | ||
"@babel-baseline/helper-compilation-targets": "npm:@babel/helper-compilation-targets@7.23.6", | ||
"@babel-baseline/helper-validator-identifier": "npm:@babel/[email protected]", | ||
"@babel-baseline/parser": "npm:@babel/parser@7.23.0", | ||
"@babel-baseline/traverse": "npm:@babel/traverse@7.23.2", | ||
"@babel-baseline/types": "npm:@babel/types@7.23.0", | ||
"@babel-baseline/parser": "npm:@babel/parser@7.24.4", | ||
"@babel-baseline/traverse": "npm:@babel/traverse@7.24.1", | ||
"@babel-baseline/types": "npm:@babel/types@7.24.0", | ||
"@babel/core": "workspace:^", | ||
"@babel/generator": "workspace:^", | ||
"@babel/helper-compilation-targets": "workspace:^", | ||
|
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
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. :)