Skip to content

Remove lodash sortBy use#13021

Merged
nicolo-ribaudo merged 6 commits intobabel:mainfrom
jridgewell:remove-lodash-sortby
Mar 25, 2021
Merged

Remove lodash sortBy use#13021
nicolo-ribaudo merged 6 commits intobabel:mainfrom
jridgewell:remove-lodash-sortby

Conversation

@jridgewell
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

JLHwung commented Mar 19, 2021

Good catch. We should add logical assignment to shippedProposals.

@nicolo-ribaudo
Copy link
Copy Markdown
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
Copy Markdown
Member Author

Does this change the behavior when _blockHoist is Infinity?

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

Copy link
Copy Markdown
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.

5 participants