Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor private name tokenizing (#13256)
* add benchmark * refactor: create tt.privateName token for private names * add backward compat privateName = hash + name to Babel 7 * perf: get private name SV from token value * chore: tweak benchmark file * chore: update test fixtures * convert tt.privateName to PrivateIdentifier * perf: avoid most isPrivateName call * Update packages/babel-parser/src/parser/expression.js Co-authored-by: Justin Ridgewell <justin@ridgewell.name> * perf: use inlinable codePointAtPos * make prettier happy Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
- Loading branch information
1 parent
278193b
commit a387973
Showing
24 changed files
with
551 additions
and
210 deletions.
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
34 changes: 34 additions & 0 deletions
34
packages/babel-parser/benchmark/many-class-private-properties/1-length.bench.mjs
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Benchmark from "benchmark"; | ||
import baseline from "@babel-baseline/parser"; | ||
import current from "../../lib/index.js"; | ||
import { report } from "../util.mjs"; | ||
|
||
const suite = new Benchmark.Suite(); | ||
// All codepoints in [0x4e00, 0x9ffc] are valid identifier name per Unicode 13 | ||
function createInput(length) { | ||
if (length > 0x9ffc - 0x4e00) { | ||
throw new Error( | ||
`Length greater than ${ | ||
0x9ffc - 0x4e00 | ||
} is not supported! Consider modify the \`createInput\`.` | ||
); | ||
} | ||
let source = "class C { "; | ||
for (let i = 0; i < length; i++) { | ||
source += "#" + String.fromCharCode(0x4e00 + i) + ";"; | ||
} | ||
return source + " }"; | ||
} | ||
function benchCases(name, implementation, options) { | ||
for (const length of [256, 512, 1024, 2048]) { | ||
const input = createInput(length); | ||
suite.add(`${name} ${length} length-1 private properties`, () => { | ||
implementation.parse(input, options); | ||
}); | ||
} | ||
} | ||
|
||
benchCases("baseline", baseline); | ||
benchCases("current", current); | ||
|
||
suite.on("cycle", report).run(); |
19 changes: 19 additions & 0 deletions
19
packages/babel-parser/benchmark/many-empty-statements/attachComment-false.bench.mjs
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Benchmark from "benchmark"; | ||
import baseline from "@babel-baseline/parser"; | ||
import current from "../../lib/index.js"; | ||
import { report } from "../util.mjs"; | ||
|
||
const suite = new Benchmark.Suite(); | ||
|
||
function benchCases(name, implementation, options) { | ||
for (const length of [256, 512, 1024, 2048]) { | ||
suite.add(`${name} ${length} empty statement`, () => { | ||
implementation.parse(";".repeat(length), options); | ||
}); | ||
} | ||
} | ||
|
||
benchCases("baseline", baseline); | ||
benchCases("current + attachComment: false", current, { attachComment: false }); | ||
|
||
suite.on("cycle", report).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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export function report(event) { | ||
const bench = event.target; | ||
const factor = bench.hz < 100 ? 100 : 1; | ||
const timeMs = bench.stats.mean * 1000; | ||
const time = | ||
timeMs < 10 | ||
? `${Math.round(timeMs * 1000) / 1000}ms` | ||
: `${Math.round(timeMs)}ms`; | ||
const msg = `${bench.name}: ${ | ||
Math.round(bench.hz * factor) / factor | ||
} ops/sec 卤${Math.round(bench.stats.rme * 100) / 100}% (${time})`; | ||
console.log(msg); | ||
} |
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.