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

[Lens] Performance refactoring for indexpattern fast lookup and Operation support matrix computation #82829

Merged
merged 14 commits into from
Nov 10, 2020

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Nov 6, 2020

Summary

Due to new validation checks being added to the Lens UI while the user performs actions (see #81439 and #82607 ) some performance tweaks have been performed to speed up lookup operations for indexpattern fields and related operations.

  • ✨ Add new getFieldByName method to the Lens' Indexpattern interface implementing a fast lookup mechanism
    • propagate the use of this new API for any indexpattern.fields.find() instance
    • replace some local lookup instances with the new API
    • reshape some components to accept the new API
  • ⚡ Refactor the getOperationSupportMatrix to be fast
  • ⚡ Reshaping getOperationSupportMatrix to use Sets instead of array for faster lookups

Fixes #82243

Before After
big-indexpattern-dnd-old big-indexpattern-dnd

the bigger contribution of performance comes from the refactor of getOperationSupportMatrix which is now taking at least 80% less time:

Before After
Screenshot 2020-11-06 at 13 21 19 Screenshot 2020-11-06 at 13 21 27

Checklist

@dej611
Copy link
Contributor Author

dej611 commented Nov 6, 2020

Profile before

Screenshot 2020-11-06 at 14 50 57

Profile after

Screenshot 2020-11-06 at 14 53 03

@dej611
Copy link
Contributor Author

dej611 commented Nov 6, 2020

The profiling and measurements above have been tested on an IndexPattern of 4000+ fields.

@dej611 dej611 added release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure labels Nov 6, 2020
@dej611
Copy link
Contributor Author

dej611 commented Nov 6, 2020

Looking also at this portion of code, which seems to waste the conditional task away: https://github.com/elastic/kibana/pull/82829/files#diff-adf4f7cb4d70d7250d44841daef76d1c7a4794a06f7ca261510e1b1112e18bb4R283-R308

Maybe there's a missing else there?

@flash1293
Copy link
Contributor

I looked into the changes and it seems like the large performance bottleneck in the support operation matrix got introduced very recently here: f0023ed

@dej611 dej611 marked this pull request as ready for review November 9, 2020 08:52
@dej611 dej611 requested a review from a team November 9, 2020 08:52
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@dej611
Copy link
Contributor Author

dej611 commented Nov 9, 2020

@elasticmachine merge upstream

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Looks pretty good, left some comments but nothing major

fieldExists(existingFields, currentIndexPattern.title, field);

function fieldNamesToOptions(items: string[]) {
return items
.map((field) => ({
label: fieldMap[field].displayName,
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem like a good handling of the error case here (it could create entries without a label) - let's filter out all fields without entry in the field map instead before mapping

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would that happen? Fields are validated against the containsData here

Copy link
Contributor

Choose a reason for hiding this comment

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

They are not for all invocations - fieldNamesToOptions is also called for empty fields in line 138 of this file.

@@ -37,16 +37,17 @@ export const getOperationSupportMatrix = (props: Props): OperationSupportMatrix

filteredOperationsByMetadata.forEach(({ operations }) => {
operations.forEach((operation) => {
// replace spread operator by regular push as it's performance wise faster
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Let's remove this comment, it won't make sense after the PR is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea was to keep it to prevent future use of spread operator again

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, got confused by the wording. Can we go with // using mutating push instead of spread operator as it's faster ?

if (operation.type === 'field') {
supportedOperationsByField[operation.field] = [
Copy link
Contributor

Choose a reason for hiding this comment

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

@wylieconlon Replacing push with a spread here happened relatively recently in a refactor PR you did (splitting up the dimension editor). Is there any reason for preferring spreading?

@@ -146,8 +146,8 @@ export function getAvailableOperationsByMetadata(indexPattern: IndexPattern) {

operationDefinitions.sort(getSortScoreByPriority).forEach((operationDefinition) => {
if (operationDefinition.input === 'field') {
indexPattern.fields.forEach((field) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see how these changes improve the code - it's still nested to the same depth (plus addToMap does not actually return something). Can you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a particular speed up here.
I did some small profiling and numbers are bit lower than with all the conditionals: seeing no harm in particular change I kept it, but it can easily reversed.

Copy link
Contributor

Choose a reason for hiding this comment

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

with all the conditionals

Which conditionals do you mean? I wasn't aware this was a performance optimization, can you explain how it could speed things up? I think I'm missing something here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant "from the previous implementations with the if/else conditionals".
It may be an anecdotal to my machine, so no strong opinion on these.

@mbondyra
Copy link
Contributor

@elasticmachine merge upstream

@mbondyra
Copy link
Contributor

Tested in Chrome, I didn't find any problems with it.

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Changes LGTM, didn't test again. Thanks for addressing all the points!

@kibanamachine
Copy link
Contributor

💚 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.0MB 1.0MB +975.0B

History

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

@dej611 dej611 merged commit 0b99841 into elastic:master Nov 10, 2020
@dej611 dej611 deleted the feature/lens/indexpattern-fields-lookup branch November 10, 2020 13:31
dej611 added a commit to dej611/kibana that referenced this pull request Nov 10, 2020
…tion support matrix computation (elastic#82829)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
phillipb added a commit to phillipb/kibana that referenced this pull request Nov 10, 2020
…kibana into bootstrap-node-details-overlay

* 'bootstrap-node-details-overlay' of github.com:phillipb/kibana: (49 commits)
  [Security Solution] Fix DNS Network table query (elastic#82778)
  [Workplace Search] Consolidate groups routes (elastic#83015)
  Adds cloud links to user menu (elastic#82803)
  [Security Solution][Detections] - follow up cleanup on auto refresh rules (elastic#83023)
  [App Search] Added the log retention panel to the Settings page (elastic#82982)
  [Maps] show icon when layer is filtered by time and allow layers to ignore global time range (elastic#83006)
  [DOCS] Consolidates drilldown pages (elastic#82081)
  [Maps] add on-prem EMS config (elastic#82525)
  migrate i18n mixin to KP (elastic#81799)
  [bundle optimization] fix imports of react-use lib (elastic#82847)
  [Discover] Add metric on adding filter (elastic#82961)
  [Lens] Performance refactoring for indexpattern fast lookup and Operation support matrix computation (elastic#82829)
  skip flaky suite (elastic#82804)
  Fix SO query for searching across spaces (elastic#83025)
  renaming built-in alerts to Stack Alerts (elastic#82873)
  [TSVB] Disable using top_hits in pipeline aggregations (elastic#82278)
  [Visualizations] Remove kui usage (elastic#82810)
  [Visualizations] Make the icon buttons labels more descriptive (elastic#82585)
  [Lens] Do not reset formatting when switching between custom ranges and auto histogram (elastic#82694)
  Fix ilm navigation (elastic#81664)
  ...
dej611 added a commit that referenced this pull request Nov 10, 2020
… Operation support matrix computation (#82829) (#83066)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Nov 10, 2020
…na into alerts/stack-alerts-public

* 'alerts/stack-alerts-public' of github.com:gmmorris/kibana:
  [Security Solution] Fix DNS Network table query (elastic#82778)
  [Workplace Search] Consolidate groups routes (elastic#83015)
  Adds cloud links to user menu (elastic#82803)
  [Security Solution][Detections] - follow up cleanup on auto refresh rules (elastic#83023)
  [App Search] Added the log retention panel to the Settings page (elastic#82982)
  [Maps] show icon when layer is filtered by time and allow layers to ignore global time range (elastic#83006)
  [DOCS] Consolidates drilldown pages (elastic#82081)
  [Maps] add on-prem EMS config (elastic#82525)
  migrate i18n mixin to KP (elastic#81799)
  [bundle optimization] fix imports of react-use lib (elastic#82847)
  [Discover] Add metric on adding filter (elastic#82961)
  [Lens] Performance refactoring for indexpattern fast lookup and Operation support matrix computation (elastic#82829)
  skip flaky suite (elastic#82804)
  Fix SO query for searching across spaces (elastic#83025)
  renaming built-in alerts to Stack Alerts (elastic#82873)
  [TSVB] Disable using top_hits in pipeline aggregations (elastic#82278)
  [Visualizations] Remove kui usage (elastic#82810)
  [Visualizations] Make the icon buttons labels more descriptive (elastic#82585)
  [Lens] Do not reset formatting when switching between custom ranges and auto histogram (elastic#82694)
:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Build index pattern field map for O(1) access
5 participants