-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Usage Collection] Small performance improvements #91467
Merged
afharo
merged 2 commits into
elastic:master
from
afharo:usage_collection/small-performance-improvement
Feb 18, 2021
Merged
[Usage Collection] Small performance improvements #91467
afharo
merged 2 commits into
elastic:master
from
afharo:usage_collection/small-performance-improvement
Feb 18, 2021
Conversation
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
afharo
added
performance
Feature:Telemetry
v7.13.0
release_note:skip
Skip the PR/issue when compiling release notes
labels
Feb 16, 2021
afharo
force-pushed
the
usage_collection/small-performance-improvement
branch
from
February 16, 2021 13:06
34fa438
to
c8b1def
Compare
afharo
force-pushed
the
usage_collection/small-performance-improvement
branch
from
February 16, 2021 13:51
c8b1def
to
f48a56c
Compare
Bamieh
approved these changes
Feb 18, 2021
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 feel these are micro-optimizations. I'd rather we'd not put time on.
- perf tests are rarely representative of real case scenarios
- As a web application there are a lot of bottlenecks (network, threads comminucation, etc). Even if we make the loops and other transformation operations literally take 0ms it will not add provide any speed improvements.
As for readabilty they are both equally readable to me so i have no preference.
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]
History
To update your PR or re-run it, just comment with: |
afharo
added a commit
to afharo/kibana
that referenced
this pull request
Feb 18, 2021
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
afharo
added a commit
that referenced
this pull request
Feb 18, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Feature:Telemetry
performance
release_note:skip
Skip the PR/issue when compiling release notes
v7.12.0
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.
Summary
This PR replaces 2 usages of
array.reduce((acc, [key, value]} => ({...acc, [key]: value}), {})
in favour ofObject.fromEntries(array.map(([key, value]) => [key, value]))
. The performance is much better on the second option, while still maintaining the declarative & non-mutating approach: https://measurethat.net/Benchmarks/Show/11657/0/arrayreduce-vs-objectfromentries-arraymapNOTE: If these changes look good, I can create an issue to follow up on catching similar usages.
Q: Should we create an eslint rule to somehow recommend the latter?
A: We shouldn't. If we add the mutation-based alternatives, there are many ways to approach this, and different browsers report different performance results. Running https://jsben.ch/UJguY in Safari vs. Chrome vs. Firefox shows that Chrome has a boosted
.reduce
+ mutation of theacc
value implementation:From left to right: Safari, Chrome, Firefox.
Checklist
Delete any items that are not applicable to this PR.
For maintainers