Skip to content

getBindingIdentifiers should return params for private methods#13723

Merged
nicolo-ribaudo merged 6 commits into
babel:mainfrom
JLHwung:fix-get-binding-identifiers
Sep 2, 2021
Merged

getBindingIdentifiers should return params for private methods#13723
nicolo-ribaudo merged 6 commits into
babel:mainfrom
JLHwung:fix-get-binding-identifiers

Conversation

@JLHwung

@JLHwung JLHwung commented Sep 1, 2021

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? t.getBindingIdentifiers does not return parameter bindings for private class methods
Patch: Bug Fix? Y
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Also include minor tweaks around scope tracking.

Performant issue

The getBindingIdentifiers is generally slow due to heavy dynamics: it even allows monkey-patching its visitor keys: getBindingIdentifiers.keys can be modified by external plugins. In my local perf test, dropping getBindingIdentifiers.keys can achieves 10x performance boost:

Details
baseline 16 binding identifiers in patterns: 61_364 ops/sec ±0.78% (0.016ms)
baseline 32 binding identifiers in patterns: 27_504 ops/sec ±1.76% (0.036ms)
baseline 64 binding identifiers in patterns: 11_901 ops/sec ±0.75% (0.084ms)
baseline 128 binding identifiers in patterns: 4_260 ops/sec ±1.49% (0.235ms)
current 16 binding identifiers in patterns: 422_790 ops/sec ±1.03% (0.002ms)
current 32 binding identifiers in patterns: 193_291 ops/sec ±1.5% (0.005ms)
current 64 binding identifiers in patterns: 75_164 ops/sec ±1.45% (0.013ms)
current 128 binding identifiers in patterns: 27_211 ops/sec ±1.04% (0.037ms)
current2 16 binding identifiers in patterns: 432_890 ops/sec ±1.55% (0.002ms)
current2 32 binding identifiers in patterns: 250_765 ops/sec ±0.94% (0.004ms)
current2 64 binding identifiers in patterns: 118_529 ops/sec ±1.45% (0.008ms)
current2 128 binding identifiers in patterns: 58_682 ops/sec ±1.88% (0.017ms)

current is new implementation inlining visitor keys, current2 is a new implementation based on current which returns bindings in tail-first order: so we can avoid unnecessary memcpy introduced by array.shift in

we should reconsider whether we are going to support getBindingIdentifiers.keys in Babel 8.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: types labels Sep 1, 2021
@babel-bot

babel-bot commented Sep 1, 2021

Copy link
Copy Markdown
Collaborator

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

@codesandbox-ci

codesandbox-ci Bot commented Sep 1, 2021

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 5bfc350:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

import Binding from "./binding";
import globals from "globals";
import {
FOR_INIT_KEYS,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice refactor here!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The FOR_INIT_KEYS is only used here. After this PR we may even remove it in Babel 8 if nobody else is using.

@nicolo-ribaudo nicolo-ribaudo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@JLHwung JLHwung force-pushed the fix-get-binding-identifiers branch from 5ab190d to 5bfc350 Compare September 2, 2021 18:19
@nicolo-ribaudo nicolo-ribaudo merged commit 51c6a99 into babel:main Sep 2, 2021
@nicolo-ribaudo nicolo-ribaudo deleted the fix-get-binding-identifiers branch September 2, 2021 19:55
@nicolo-ribaudo nicolo-ribaudo changed the title getBindingIdentifiers should return params for private methods getBindingIdentifiers should return params for private methods Sep 2, 2021
@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 Dec 3, 2021
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Dec 3, 2021
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: types PR: Bug Fix 🐛 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