refactor: drop lodash for lib/theme - #3807
Conversation
|
According to benchmark performed by Travis CI, this PR makes generation speed 3x slower. |
f093749 to
7928973
Compare
|
|
||
| this.i18n = new I18n({ | ||
| languages: _(languages).compact().uniq().value() | ||
| languages: [...new Set(languages.filter(Boolean))] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
value() is a lodash method, which is used to get value from lodash wrapped prototype chain.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
That seems like the last suspect now. what about return Object.assign({}, locals, locals.prototype, data, { ? (source)
There was a problem hiding this comment.
@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.
4fd4a9f to
10d8fb7
Compare
What does it do?
This PR is a part of #3753
How to test
Screenshots
Pull request tasks