Skip to content

Reorganize token types and use a map for them#9645

Merged
danez merged 1 commit intobabel:masterfrom
danez:better-token-types
Mar 6, 2019
Merged

Reorganize token types and use a map for them#9645
danez merged 1 commit intobabel:masterfrom
danez:better-token-types

Conversation

@danez
Copy link
Member

@danez danez commented Mar 6, 2019

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

This reorganizes and improves the keyword token types a bit. (At least to me it is a little bit clearer)
I converted the keyword Object.create(null, {...}) to a Map, which seems more straight forward. This also allows us to use the same Map in identifier.js and we do not have to define keywords twice.

Unrelated I added a comment to the jsx plugin, about something noticed while debugging the jest issue.

@danez danez added PR: Polish 💅 A type of pull request used for our changelog categories pkg: parser labels Mar 6, 2019
@babel-bot
Copy link
Collaborator

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

1 similar comment
@babel-bot
Copy link
Collaborator

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

const DECIMAL_NUMBER = /^\d+$/;

// Be aware that this file is always executed and not only when the plugin is enabled.
// Therefore this contexts and tokens do always exist.
Copy link
Member

Choose a reason for hiding this comment

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

In a followup PR, maybe we should move those definitions to the plugin constructor so they are only defined when needed.

@danez danez merged commit d8a5329 into babel:master Mar 6, 2019
@danez danez deleted the better-token-types branch March 6, 2019 22:30
readWord(): void {
const word = this.readWord1();
const type = keywordTypes[word] || tt.name;
const type = keywordTypes.get(word) || tt.name;
Copy link
Member

Choose a reason for hiding this comment

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

This may be a performance regression.

Copy link
Member Author

@danez danez Mar 7, 2019

Choose a reason for hiding this comment

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

Maps seem to have improved a lot. I did run some performance tests and the results seem to be not worse than before, maybe even better sligthly.

(oldParser is before the commit, babelParser is with, both parsers are tested twice, because I don't trust the benchmark :D )

~/Documents/Github/babylon_performance master* 1m 14s
❯ node --expose-gc index.js
Node: v10.15.1
Running test suite for ember.debug.js ...
Running test suite for jquery.js ...
Running test suite for angular.js ...
Running test suite for babylon-dist.js ...
Running test suite for backbone.js ...
Running test suite for react-with-addons.js ...
┌──────────────────────┬──────────────────────────────────┬──────────────────────────────────┬──────────────────────────────────┬──────────────────────────────────┐
│ fixture              │ oldBabelParser                   │ babelParser                      │ oldBabelParser2                  │ babelParser2                     │
├──────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ ember.debug.js       │ 5.76 ops/sec ±3.89% (mean 174ms) │ 5.91 ops/sec ±6% (mean 169ms)    │ 5.91 ops/sec ±4.23% (mean 169ms) │ 6.01 ops/sec ±6.28% (mean 167ms) │
├──────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ jquery.js            │ 30.86 ops/sec ±6.3% (mean 32ms)  │ 32.06 ops/sec ±4.57% (mean 31ms) │ 30.81 ops/sec ±8.21% (mean 32ms) │ 32.09 ops/sec ±6.96% (mean 31ms) │
├──────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ angular.js           │ 14.64 ops/sec ±6.39% (mean 68ms) │ 15.71 ops/sec ±5.11% (mean 64ms) │ 15.32 ops/sec ±5.51% (mean 65ms) │ 16.04 ops/sec ±5.1% (mean 62ms)  │
├──────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ babylon-dist.js      │ 23.97 ops/sec ±5.25% (mean 42ms) │ 25.62 ops/sec ±6.37% (mean 39ms) │ 24.61 ops/sec ±7.03% (mean 41ms) │ 26.07 ops/sec ±5.72% (mean 38ms) │
├──────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ backbone.js          │ 145 ops/sec ±5.43% (mean 7ms)    │ 148 ops/sec ±5.29% (mean 7ms)    │ 147 ops/sec ±5.4% (mean 7ms)     │ 153 ops/sec ±5.17% (mean 7ms)    │
├──────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ react-with-addons.js │ 13.84 ops/sec ±6.23% (mean 72ms) │ 14.64 ops/sec ±5.84% (mean 68ms) │ 13.96 ops/sec ±6.96% (mean 72ms) │ 14.33 ops/sec ±6.56% (mean 70ms) │
└──────────────────────┴──────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────┘
❯ node --expose-gc index.js
Node: v8.15.0
Running test suite for ember.debug.js ...
Running test suite for jquery.js ...
Running test suite for angular.js ...
Running test suite for babylon-dist.js ...
Running test suite for backbone.js ...
Running test suite for react-with-addons.js ...
┌──────────────────────┬──────────────────────────────────┬──────────────────────────────────┬──────────────────────────────────┬──────────────────────────────────┐
│ fixture              │ oldBabelParser                   │ babelParser                      │ oldBabelParser2                  │ babelParser2                     │
├──────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ ember.debug.js       │ 5.37 ops/sec ±5.67% (mean 186ms) │ 5.7 ops/sec ±5.39% (mean 175ms)  │ 5.23 ops/sec ±5.85% (mean 191ms) │ 5.79 ops/sec ±5.93% (mean 173ms) │
├──────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ jquery.js            │ 29.75 ops/sec ±5.67% (mean 34ms) │ 31.5 ops/sec ±5.42% (mean 32ms)  │ 29.77 ops/sec ±5.85% (mean 34ms) │ 31.73 ops/sec ±4.97% (mean 32ms) │
├──────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ angular.js           │ 14.49 ops/sec ±6.1% (mean 69ms)  │ 15.2 ops/sec ±5.99% (mean 66ms)  │ 14.68 ops/sec ±6.05% (mean 68ms) │ 15.35 ops/sec ±6.12% (mean 65ms) │
├──────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ babylon-dist.js      │ 23.84 ops/sec ±5.05% (mean 42ms) │ 24.93 ops/sec ±5.12% (mean 40ms) │ 22.37 ops/sec ±6.16% (mean 45ms) │ 26.17 ops/sec ±5.65% (mean 38ms) │
├──────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ backbone.js          │ 134 ops/sec ±5.73% (mean 7ms)    │ 149 ops/sec ±4.87% (mean 7ms)    │ 141 ops/sec ±4.71% (mean 7ms)    │ 151 ops/sec ±4.46% (mean 7ms)    │
├──────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ react-with-addons.js │ 13.47 ops/sec ±6.02% (mean 74ms) │ 14.02 ops/sec ±7.15% (mean 71ms) │ 13.58 ops/sec ±6.63% (mean 74ms) │ 14.6 ops/sec ±6.69% (mean 68ms)  │
└──────────────────────┴──────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────┘

I couldn't test node 6 because it segfaults when I run the benchmark.

Copy link
Member

Choose a reason for hiding this comment

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

Works for me!

mAAdhaTTah added a commit to mAAdhaTTah/babel that referenced this pull request Mar 15, 2019
* master: (58 commits)
  Remove dependency on home-or-tmp package (babel#9678)
  [proposal-object-rest-spread] fix templateLiteral in extractNormalizedKeys (babel#9628)
  Partial application plugin (babel#9474)
  Private Static Class Methods (Stage 3) (babel#9446)
  gulp-uglify@3.0.2
  rollup@1.6.0
  eslint@5.15.1
  jest@24.5.0
  regexpu-core@4.5.4
  Remove input and length from state (babel#9646)
  Switch from rollup-stream to rollup and update deps (babel#9640)
  System modules - Hoist classes like other variables (babel#9639)
  fix: Don't transpile ES2018 symbol properties (babel#9650)
  Add WarningsToErrorsPlugin to webpack to avoid missing build problems on CI (babel#9647)
  Update regexpu-core dependency (babel#9642)
  Add placeholders support to @babel/types and @babel/generator (babel#9542)
  Generate plugins file
  Make babel-standalone an ESModule and enable flow (babel#9025)
  Reorganize token types and use a map for them (babel#9645)
  [TS] Allow context type annotation on getters/setters (babel#9641)
  ...
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 4, 2019
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: Polish 💅 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants