Skip to content

[unified search] optimize async chunk loading#214483

Merged
nreese merged 22 commits intoelastic:mainfrom
nreese:unified_search_single_chunk
Mar 27, 2025
Merged

[unified search] optimize async chunk loading#214483
nreese merged 22 commits intoelastic:mainfrom
nreese:unified_search_single_chunk

Conversation

@nreese
Copy link
Contributor

@nreese nreese commented Mar 13, 2025

PR reduces unifiedSearch chunks into ui chunk, action chunk, and a autocomplete chunk.

Before

Screenshot 2025-03-14 at 8 47 10 AM

After

The second chunk request is because search bar loads KQL suggestions. This will be addressed in a follow up PR and the search bar will lazy load suggestions only when interacted with.
Screenshot 2025-03-14 at 12 56 28 PM

@nreese
Copy link
Contributor Author

nreese commented Mar 13, 2025

/ci

@nreese
Copy link
Contributor Author

nreese commented Mar 13, 2025

/ci

@nreese
Copy link
Contributor Author

nreese commented Mar 14, 2025

/ci

@nreese
Copy link
Contributor Author

nreese commented Mar 14, 2025

/ci

order: 1,
mount: async (params) => {
const { renderApp, services, store } = await mountDependencies();
const { ManagementSettings } = await this.lazyAssistantSettingsManagement();
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 part of fix but I saw this while in the file. This creates a waterfall of chunk loading. I moved ManagementSettings chunk loading into mountDependencies to avoid this waterfall.

@nreese
Copy link
Contributor Author

nreese commented Mar 14, 2025

/ci

@nreese nreese changed the title [unified search] load unified search in single chunk [unified search] optimize async chunk loading Mar 14, 2025
@nreese
Copy link
Contributor Author

nreese commented Mar 14, 2025

@elasticmachine merge upstream

@nreese
Copy link
Contributor Author

nreese commented Mar 14, 2025

/ci

1 similar comment
@nreese
Copy link
Contributor Author

nreese commented Mar 14, 2025

/ci

@nreese nreese added Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas t// release_note:skip Skip the PR/issue when compiling release notes backport:version Backport to applied version labels v9.1.0 v8.19.0 labels Mar 14, 2025
@nreese nreese marked this pull request as ready for review March 14, 2025 21:00
@nreese nreese requested a review from a team as a code owner March 14, 2025 21:00
await this.registerActions(store, params.history, core, services);
if (!this._actionsRegistered) {
this._actionsRegistered = true;
registerActions(store, params.history, core, services);
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this function async now? Don't you think we should await?

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 results of registerActions are not used so I did not think an await was needed. I will defer to your team if await is required. Just let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

This function is async now because you changed that here

Does this really need to be async?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this really need to be async?

Yes, because createFilterAction from import { createFilterAction } from '@kbn/unified-search-plugin/public'; is now async to avoid including createFilterAction in unifiedSearch bundle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added await e1bba66

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, but this is not awaiting anything unless we also await the registerDiscoverHistogramActions call inside registerUIActions, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

registerUIActions needs to be async so that registerDiscoverHistogramActions can be async. Let me know if you have any further questions

Copy link
Contributor

Choose a reason for hiding this comment

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

@nreese Sure, let me rephrase the question.

Why is the registerDiscoverHistogramActions() call not awaited here?

registerDiscoverHistogramActions(store, history, coreSetup, services);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for clarifying, added await 98fc7a7

Copy link
Contributor

@semd semd left a comment

Choose a reason for hiding this comment

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

LGTM

@nreese
Copy link
Contributor Author

nreese commented Mar 26, 2025

@elasticmachine merge upstream

@elastic-vault-github-plugin-prod elastic-vault-github-plugin-prod bot requested a review from a team as a code owner March 26, 2025 14:51
@nreese
Copy link
Contributor Author

nreese commented Mar 26, 2025

@elasticmachine merge upstream

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

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

Tested this locally in chrome and looked through the code. Nice clean change list, great bundle reductions, and a good start to our ownership of Unified Search.

Changes LGTM! Left a few small comments.

unifiedDocViewer: 25099
unifiedHistogram: 19928
unifiedSearch: 71059
unifiedSearch: 23000
Copy link
Contributor

Choose a reason for hiding this comment

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

Great to see this coming down!

@@ -42,9 +42,7 @@ interface State {
fieldLabel?: string;
}

// Needed for React.lazy
// eslint-disable-next-line import/no-default-export
export default class ApplyFiltersPopoverContent extends Component<Props, State> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Good to see this loaded async with the action definition rather than via React lazy.

* the withSuspense` HOC to load this component.
*/
export const DataViewsListLazy = React.lazy(() => import('./dataview_list'));
export const DataViewsListLazy = React.lazy(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Eventually it would be good to have these exported with their own load states rather than forcing the consumer to use suspense and provide a fallback.


// Needed for React.lazy
// eslint-disable-next-line import/no-default-export
export default FilterBadgeGroup;
Copy link
Contributor

Choose a reason for hiding this comment

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

Great to see the return { default: Component } syntax used for the lazy loading rather than disabling our no-default-export rule.

export { QuerySuggestionTypes } from './autocomplete/providers/query_suggestion_provider';

import { UnifiedSearchPublicPlugin } from './plugin';
export async function createFilterAction(
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 this is used specifically in Discover. Seems like a strange use case to import an action definition from another plugin and register it again. It's probably out of scope for this PR to separate it out or fix this up but it's definitely a bit of a code smell.

For instance, why can't the trigger just get the actions from a different trigger or get the apply filter action from the registry?

@nreese
Copy link
Contributor Author

nreese commented Mar 26, 2025

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #72 / InfraOps App Metrics UI Infrastructure Source Configuration with metrics present renders the waffle map
  • [job] [logs] FTR Configs #97 / Security Solution - Telemetry Security Telemetry - Indices metadata task telemetry @ess @serverless indices metadata should publish data stream events

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
securitySolution 8.9MB 8.9MB +60.0B
unifiedSearch 350.8KB 351.2KB +483.0B
total +543.0B

Page load bundle

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

id before after diff
securitySolution 88.5KB 88.5KB +6.0B
unifiedSearch 36.6KB 22.0KB -14.6KB
total -14.6KB
Unknown metric groups

async chunk count

id before after diff
unifiedSearch 21 4 -17

ESLint disabled line counts

id before after diff
unifiedSearch 23 8 -15

References to deprecated APIs

id before after diff
unifiedSearch 15 13 -2

Total ESLint disabled count

id before after diff
unifiedSearch 23 8 -15

History

@nreese nreese merged commit 3bc1465 into elastic:main Mar 27, 2025
10 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/14096285966

kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Mar 27, 2025
PR reduces unifiedSearch chunks into ui chunk, action chunk, and a
autocomplete chunk.

### Before
<img width="350" alt="Screenshot 2025-03-14 at 8 47 10 AM"
src="https://github.com/user-attachments/assets/f54fe21e-7548-48a1-8874-e36377826701"
/>

### After
The second chunk request is because search bar loads KQL suggestions.
This will be addressed in a follow up PR and the search bar will lazy
load suggestions only when interacted with.
<img width="350" alt="Screenshot 2025-03-14 at 12 56 28 PM"
src="https://github.com/user-attachments/assets/8f23ee56-a57a-489b-aeab-caa30f739d03"
/>

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
(cherry picked from commit 3bc1465)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

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

Questions ?

Please refer to the Backport tool documentation

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 31, 2025
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

kibanamachine added a commit that referenced this pull request Mar 31, 2025
# Backport

This will backport the following commits from `main` to `8.x`:
- [[unified search] optimize async chunk loading
(#214483)](#214483)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Nathan
Reese","email":"reese.nathan@elastic.co"},"sourceCommit":{"committedDate":"2025-03-27T00:39:58Z","message":"[unified
search] optimize async chunk loading (#214483)\n\nPR reduces
unifiedSearch chunks into ui chunk, action chunk, and a\nautocomplete
chunk.\n\n### Before\n<img width=\"350\" alt=\"Screenshot 2025-03-14 at
8 47
10 AM\"\nsrc=\"https://github.com/user-attachments/assets/f54fe21e-7548-48a1-8874-e36377826701\"\n/>\n\n###
After\nThe second chunk request is because search bar loads KQL
suggestions.\nThis will be addressed in a follow up PR and the search
bar will lazy\nload suggestions only when interacted with.\n<img
width=\"350\" alt=\"Screenshot 2025-03-14 at 12 56
28 PM\"\nsrc=\"https://github.com/user-attachments/assets/8f23ee56-a57a-489b-aeab-caa30f739d03\"\n/>\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"3bc1465365872d093a9e8ff5666ab0b01738c792","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Presentation","release_note:skip","backport:version","v9.1.0","v8.19.0"],"title":"[unified
search] optimize async chunk
loading","number":214483,"url":"https://github.com/elastic/kibana/pull/214483","mergeCommit":{"message":"[unified
search] optimize async chunk loading (#214483)\n\nPR reduces
unifiedSearch chunks into ui chunk, action chunk, and a\nautocomplete
chunk.\n\n### Before\n<img width=\"350\" alt=\"Screenshot 2025-03-14 at
8 47
10 AM\"\nsrc=\"https://github.com/user-attachments/assets/f54fe21e-7548-48a1-8874-e36377826701\"\n/>\n\n###
After\nThe second chunk request is because search bar loads KQL
suggestions.\nThis will be addressed in a follow up PR and the search
bar will lazy\nload suggestions only when interacted with.\n<img
width=\"350\" alt=\"Screenshot 2025-03-14 at 12 56
28 PM\"\nsrc=\"https://github.com/user-attachments/assets/8f23ee56-a57a-489b-aeab-caa30f739d03\"\n/>\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"3bc1465365872d093a9e8ff5666ab0b01738c792"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/214483","number":214483,"mergeCommit":{"message":"[unified
search] optimize async chunk loading (#214483)\n\nPR reduces
unifiedSearch chunks into ui chunk, action chunk, and a\nautocomplete
chunk.\n\n### Before\n<img width=\"350\" alt=\"Screenshot 2025-03-14 at
8 47
10 AM\"\nsrc=\"https://github.com/user-attachments/assets/f54fe21e-7548-48a1-8874-e36377826701\"\n/>\n\n###
After\nThe second chunk request is because search bar loads KQL
suggestions.\nThis will be addressed in a follow up PR and the search
bar will lazy\nload suggestions only when interacted with.\n<img
width=\"350\" alt=\"Screenshot 2025-03-14 at 12 56
28 PM\"\nsrc=\"https://github.com/user-attachments/assets/8f23ee56-a57a-489b-aeab-caa30f739d03\"\n/>\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"3bc1465365872d093a9e8ff5666ab0b01738c792"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Nathan Reese <reese.nathan@elastic.co>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 31, 2025
cqliu1 pushed a commit to cqliu1/kibana that referenced this pull request Mar 31, 2025
PR reduces unifiedSearch chunks into ui chunk, action chunk, and a
autocomplete chunk.

### Before
<img width="350" alt="Screenshot 2025-03-14 at 8 47 10 AM"
src="https://github.com/user-attachments/assets/f54fe21e-7548-48a1-8874-e36377826701"
/>

### After
The second chunk request is because search bar loads KQL suggestions.
This will be addressed in a follow up PR and the search bar will lazy
load suggestions only when interacted with.
<img width="350" alt="Screenshot 2025-03-14 at 12 56 28 PM"
src="https://github.com/user-attachments/assets/8f23ee56-a57a-489b-aeab-caa30f739d03"
/>

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas t// v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants