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

Increase flatten performance of SearchSource #150658

Merged

Conversation

kertal
Copy link
Member

@kertal kertal commented Feb 9, 2023

Summary

This PR improves the performance of flattening the requested fields of the search source data request. it replaces the use of lodash uniqWith with a different implementation reducing the amount of iteration, which improves performance a lot when there are many fields. So when I tested with a data view having about 10.000 fields the time used for this loop went from 130-150ms to 2.3-4.1 ms

Bildschirmfoto 2023-02-13 um 21 26 30

Bildschirmfoto 2023-02-13 um 21 27 28

However it's important to note that this it just improved when there are field filters in the data view set. Else the improved part of the code isn't hit.

Fixes #136854

@kertal kertal self-assigned this Feb 9, 2023
@kertal kertal added Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. release_note:skip Skip the PR/issue when compiling release notes performance Feature:Search Querying infrastructure in Kibana labels Feb 14, 2023
@kertal kertal changed the title Search source increase flatten performance Increase flatten performance of SearchSource Feb 14, 2023
@kertal kertal marked this pull request as ready for review February 14, 2023 17:58
@kertal kertal requested review from a team as code owners February 14, 2023 17:58
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

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

Great! Thanks for improving the performance! 👏


const uniqueFieldNames = new Set();
const uniqueFields = [];
for (const field of bodyFields.concat(filteredDocvalueFields)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also change to forEach here instead of for to minimize event loop blocking.

Copy link
Member Author

Choose a reason for hiding this comment

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

thx, you mean?

bodyFields.concat(filteredDocvalueFields).forEach right? wouldn't this also block the event loop?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. Well, it will block in chunks but it might also allow some browser work in between. Or maybe I am just making this up 😀

Copy link
Member Author

@kertal kertal Feb 16, 2023

Choose a reason for hiding this comment

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

I think it would be the case if it was an async/await type of forEach, but here I think it's blocking the even loop until done (pls prove me wrong 😃 )

@kertal
Copy link
Member Author

kertal commented Feb 15, 2023

@elasticmachine merge upstream

@kertal
Copy link
Member Author

kertal commented Feb 16, 2023

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Page load bundle

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

id before after diff
data 407.4KB 407.4KB -54.0B

History

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

cc @kertal

@kertal kertal merged commit 2406ada into elastic:main Feb 16, 2023
@kertal kertal deleted the search-source-increase-flatten-performance branch February 16, 2023 19:03
@kibanamachine kibanamachine added v8.8.0 backport:skip This commit does not require backporting labels Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Search Querying infrastructure in Kibana performance release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve performance of searchsource flattening
5 participants