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

Fix multi terms performance bottleneck #126575

Merged
merged 3 commits into from
Mar 3, 2022

Conversation

flash1293
Copy link
Contributor

This PR drastically reduces the number of times new formatter instances as constructed, speeding up rendering of chart with lots of data points especially if they are using multi terms (because it would instantiate new formatter instances for each part of the key from scratch on each formatting).

Before:
Screenshot 2022-03-01 at 12 58 01

After:
Screenshot 2022-03-01 at 13 20 20

There are a few other things to improve but those are to most relevant ones.

@flash1293 flash1293 added Team:Visualizations Visualization editors, elastic-charts and infrastructure Team:AppServicesSv release_note:skip Skip the PR/issue when compiling release notes Feature:Lens auto-backport Deprecated - use backport:version if exact versions are needed v8.1.0 v8.2.0 labels Mar 1, 2022
@flash1293 flash1293 marked this pull request as ready for review March 1, 2022 16:23
@flash1293 flash1293 requested review from a team as code owners March 1, 2022 16:23
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-vis-editors @elastic/kibana-vis-editors-external (Team:VisEditors)

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServicesSv)

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review 👍
Left just a minor nitpick comment.
Will test it locally now

Comment on lines +142 to +148
const isCached = this.formatCache.has(fieldParams);
const cachedFormat =
this.formatCache.get(fieldParams) ||
getFieldFormat({ id: fieldParams.id, params: fieldParams });
if (!isCached) {
this.formatCache.set(fieldParams, cachedFormat);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: inverting the order will remove few lines

Suggested change
const isCached = this.formatCache.has(fieldParams);
const cachedFormat =
this.formatCache.get(fieldParams) ||
getFieldFormat({ id: fieldParams.id, params: fieldParams });
if (!isCached) {
this.formatCache.set(fieldParams, cachedFormat);
}
if (!this.formatCache.has(fieldParams);) {
this.formatCache.set(
fieldParams,
getFieldFormat({ id: fieldParams.id, params: fieldParams })
);
}
return this.formatCache.get(fieldParams);

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 1.1MB 1.1MB +111.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 452.4KB 452.5KB +131.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code LGTM

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally in Safari and cannot break it.
On the other note I could not reproduce the initial performance problem either while testing side by side with an instance from main

@flash1293 flash1293 merged commit 555ec91 into elastic:main Mar 3, 2022
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 3, 2022
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.1

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Mar 3, 2022
(cherry picked from commit 555ec91)

Co-authored-by: Joe Reuter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.1.0 v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants