-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Closed
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7a11831
refactor: drop lodash for lib/theme/index.js
SukkaW a78c945
refactor: drop lodash for lib/theme/view.js
SukkaW ca1d189
refactor: replace concat() with push()
SukkaW fc140bd
refactor: ES6 syntax
SukkaW d0d45dc
refactor: another implement of _.omit
SukkaW 7928973
refactor: simplify assignIn
SukkaW 673cf86
refactor: replace spread syntax with Array.from
SukkaW 54687bc
revert: temporarily revert to lodash
SukkaW 10d8fb7
revert back to ES6 syntax
SukkaW 3d3d41b
expriment: use lodash.assign instead of Object.assign
SukkaW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 oflanguages
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value()
is a lodash method, which is used to get value from lodash wrapped prototype chain.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@curbengh I have done through some investigation about performance of
Object.assign
. It seems thatObject.assign
will meet performance issue when facing large object. Even Node.js itself is still using the deprecatedutil._extend
, because it is still a lot more faster thanObject.assign
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like the last suspect now. what about
return Object.assign({}, locals, locals.prototype, data, {
? (source)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@curbengh In fact I have tried
local.prototype
at very beginning but it won't pass the test. Thelocals
here is differentwith a constructor.