Skip to content
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

Remove lodash sortBy use #13021

Merged
merged 6 commits into from Mar 25, 2021
Merged

Conversation

jridgewell
Copy link
Member

This one require increases startup time by ~100ms (coming from loadOptions).

Screen Shot 2021-03-18 at 3 33 56 PM

Re: #11726

This one `require` increases startup time by 100ms (coming from `loadOptions`).
@babel-bot
Copy link
Collaborator

babel-bot commented Mar 18, 2021

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 18, 2021

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 23da89c:

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

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

lodash/sort is stable. However, Array#sort is not stable util V8 7.0. We can polyfill it by lodash sortBy on Node.js < 11 like we did for other features:

babel/babel.config.js

Lines 259 to 270 in 21e8e59

replacement: template({ syntacticPlaceholders: true })`
((v,w)=>(v=v.split("."),w=w.split("."),+v[0]>+w[0]||v[0]==w[0]&&+v[1]>=+w[1]))(process.versions.node, "8.9")
? require.resolve
: (/* request */ r, { paths: [/* base */ b] }, M = require("module")) => {
let /* filename */ f = M._findPath(r, M._nodeModulePaths(b).concat(b));
if (f) return f;
f = new Error(\`Cannot resolve module '\${r}'\`);
f.code = "MODULE_NOT_FOUND";
throw f;
}
`,
},

Hopefully we can switch to Array#sort in Babel 8.

@jridgewell
Copy link
Member Author

We can polyfill it by lodash sortBy on Node.js < 11 like we did for other features

I added a simple bucket sorter. And it's faster! https://jsbench.github.io/#f32d70e88170ab4e165ac1f7f30df163

@JLHwung
Copy link
Contributor

JLHwung commented Mar 19, 2021

Good catch. We should add logical assignment to shippedProposals.

@nicolo-ribaudo
Copy link
Member

Does this change the behavior when _blockHoist is Infinity?

@nicolo-ribaudo nicolo-ribaudo added the PR: Internal 🏠 A type of pull request used for our changelog categories label Mar 19, 2021
@jridgewell
Copy link
Member Author

Does this change the behavior when _blockHoist is Infinity?

You're right. I've updated to not use an array.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Thanks!

@nicolo-ribaudo nicolo-ribaudo merged commit 327b4ce into babel:main Mar 25, 2021
@jridgewell jridgewell deleted the remove-lodash-sortby branch March 25, 2021 21:23
@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 Jun 25, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 25, 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 PR: Internal 🏠 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants