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

New faster _.extend alternative #244

Open
wants to merge 1 commit into
base: master
from

Conversation

@SukkaW
Copy link

SukkaW commented Dec 16, 2019

During the process of dropping lodash for hexo project, we have faced serious obstacles when replacing lodash.assignIn with native javascript. We have tried the example function from the README but soon run into serious performance regression. After some investigations, it turns out that the Object.getPrototypeOf() is the culprit.

After trying Object.getPrototypeOf(), Reflect.getPrototypeOf() even the deprecated __proto__, the performance regression remains. We finally drops lodash.assignIn (hexojs/hexo#3969) with a pure javascript alternative without bringing in any performance regression. It proves that for...in... is still the fastest way to iterate over the properties of an object.

@coveralls

This comment has been minimized.

Copy link

coveralls commented Dec 16, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 4826a61 on SukkaW:faster-extend into 5665d8a on you-dont-need:master.

@stevemao stevemao requested review from ODudek, cjtaylor1990 and cylim Dec 16, 2019
Copy link
Contributor

cjtaylor1990 left a comment

Hmmm...this is an interesting observation, and obviously something we need to keep in mind if we want to make this plugin something people will use.

I personally think this is a fine addition given the performance boost.

})
return Object.assign(target, ...source)

const extend = (...args) => {

This comment has been minimized.

Copy link
@ODudek

ODudek Dec 30, 2019

Member

This code still can be optimized. You don't need 3rd loop, you can do obj[key] = source[key]; in for..in loop and it's much faster.

This comment has been minimized.

Copy link
@SukkaW

SukkaW Dec 30, 2019

Author

@ODudek Yeah, you are right.

I do optimize the function in hexojs/hexo#3987, but I forget this PR. I will update this PR to newest then.

@SukkaW SukkaW force-pushed the SukkaW:faster-extend branch from 419ea3b to 4826a61 Dec 30, 2019
@SukkaW SukkaW requested a review from ODudek Dec 30, 2019
@ODudek
ODudek approved these changes Dec 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.