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

refactor: drop lodash for lib/theme #3807

Closed
wants to merge 10 commits into from

Conversation

@SukkaW
Copy link
Member

SukkaW commented Oct 27, 2019

What does it do?

This PR is a part of #3753

How to test

git clone -b drop-lodash-lib-theme https://github.com/sukkaw/hexo.git
cd hexo
npm install
npm test

Screenshots

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.
@SukkaW SukkaW requested review from segayuu and curbengh Oct 27, 2019
@SukkaW SukkaW added this to To do in Replace lodash with native API via automation Oct 27, 2019
@SukkaW

This comment has been minimized.

Copy link
Member Author

SukkaW commented Oct 27, 2019

According to benchmark performed by Travis CI, this PR makes generation speed 3x slower.

@coveralls

This comment has been minimized.

Copy link

coveralls commented Oct 27, 2019

Coverage Status

Coverage decreased (-0.002%) to 97.265% when pulling 3d3d41b on SukkaW:drop-lodash-lib-theme into 17c2bbb on hexojs:master.

lib/theme/view.js Outdated Show resolved Hide resolved
SukkaW added 4 commits Oct 27, 2019
@SukkaW SukkaW force-pushed the SukkaW:drop-lodash-lib-theme branch from f093749 to 7928973 Oct 27, 2019
@@ -28,7 +27,7 @@ function Theme(ctx) {
languages.push('default');

this.i18n = new I18n({
languages: _(languages).compact().uniq().value()
languages: [...new Set(languages.filter(Boolean))]

This comment has been minimized.

Copy link
@curbengh

curbengh Oct 27, 2019

Contributor

what about Array.from(new Set(languages.filter(Boolean)))?

I wonder if value() is needed, I can't find it in lodash doc, perhaps it's a function of languages?

This comment has been minimized.

Copy link
@SukkaW

SukkaW Oct 27, 2019

Author Member

value() is a lodash method, which is used to get value from lodash wrapped prototype chain.

This comment has been minimized.

Copy link
@SukkaW

SukkaW Oct 27, 2019

Author Member

I have make a benchmark at jsPerf: https://jsperf.com/lodash-uniq-vs-javascript-set/1

It seems the diffrence between Array.from & spread syntax is negligible, at least in browser.

This comment has been minimized.

Copy link
@curbengh

curbengh Oct 27, 2019

Contributor

I see.

The travis benchmark showed the spread syntax is the source of regression. I noticed you reverted the last commit; to confirm the source?

This comment has been minimized.

Copy link
@curbengh

curbengh Oct 27, 2019

Contributor

It seems the diffrence between Array.from & spread syntax is negligible, at least in browser.

Similar result in travis too. Can you try revert back to lodash just for this line? to test whether Set() is the culprit.

This comment has been minimized.

Copy link
@curbengh

curbengh Oct 27, 2019

Contributor

But that doesn't explain why lodash is faster in view.js.


btw, as for the lib/theme, I think it's fine to use Set() since languages array would only have 2 elements max, so it wouldn't (and shouldn't) make any difference.

This comment has been minimized.

Copy link
@SukkaW

SukkaW Oct 27, 2019

Author Member

@curbengh I have done through some investigation about performance of Object.assign. It seems that Object.assign will meet performance issue when facing large object. Even Node.js itself is still using the deprecated util._extend, because it is still a lot more faster than Object.assign.

This comment has been minimized.

Copy link
@SukkaW

SukkaW Oct 27, 2019

Author Member

A bit more interesting... Even if I replace Object.assign with lodash.assign, the impact is still there. So maybe the problem is at Object.getPrototypeOf..

This comment has been minimized.

Copy link
@curbengh

curbengh Oct 27, 2019

Contributor

That seems like the last suspect now. what about return Object.assign({}, locals, locals.prototype, data, { ? (source)

This comment has been minimized.

Copy link
@SukkaW

SukkaW Oct 27, 2019

Author Member

@curbengh In fact I have tried local.prototype at very beginning but it won't pass the test. The locals here is differentwith a constructor.

@SukkaW SukkaW force-pushed the SukkaW:drop-lodash-lib-theme branch from 4fd4a9f to 10d8fb7 Oct 27, 2019
@SukkaW SukkaW closed this Oct 27, 2019
Replace lodash with native API automation moved this from To do to Done Oct 27, 2019
@SukkaW SukkaW mentioned this pull request Oct 27, 2019
0 of 2 tasks complete
@curbengh curbengh mentioned this pull request Dec 13, 2019
0 of 2 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.