Skip to content

Commit

Permalink
[8.x] [ML] Data Visualizer: Optimize initial load bundles. (#199029) (#…
Browse files Browse the repository at this point in the history
…199663)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ML] Data Visualizer: Optimize initial load bundles.
(#199029)](#199029)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Walter
Rafelsberger","email":"walter.rafelsberger@elastic.co"},"sourceCommit":{"committedDate":"2024-11-11T15:38:01Z","message":"[ML]
Data Visualizer: Optimize initial load bundles. (#199029)\n\n##
Summary\r\n\r\nPart of
https://github.com/elastic/kibana/issues/194171.\r\n\r\nThe
`dataVisualizer` plugin loads quite some bundle chunks on the
first\r\nKibana load. On `main` it currently looks like this on page
load:\r\n\r\n![CleanShot 2024-11-05 at 17
51\r\n35@2x](https://github.com/user-attachments/assets/7b2fcc7e-08fb-48b8-a1d9-03063b555e38)\r\n\r\nThis
PR refactors how embeddables and UI actions get initialized to\r\navoid
loading any additional async bundles on page load.\r\n\r\n![CleanShot
2024-11-06 at 10
51\r\n36@2x](https://github.com/user-attachments/assets/019c3c79-49b5-4e63-9b94-3d7b02963a9b)\r\n\r\n###
Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [x] This was checked for breaking
API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)","sha":"aa4f430ed59694b7f8c3d5b318c76e6aef95331e","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":[":ml","release_note:skip","Feature:File
and Index Data Viz","v9.0.0","backport:version","v8.17.0"],"title":"[ML]
Data Visualizer: Optimize initial load
bundles.","number":199029,"url":"https://github.com/elastic/kibana/pull/199029","mergeCommit":{"message":"[ML]
Data Visualizer: Optimize initial load bundles. (#199029)\n\n##
Summary\r\n\r\nPart of
https://github.com/elastic/kibana/issues/194171.\r\n\r\nThe
`dataVisualizer` plugin loads quite some bundle chunks on the
first\r\nKibana load. On `main` it currently looks like this on page
load:\r\n\r\n![CleanShot 2024-11-05 at 17
51\r\n35@2x](https://github.com/user-attachments/assets/7b2fcc7e-08fb-48b8-a1d9-03063b555e38)\r\n\r\nThis
PR refactors how embeddables and UI actions get initialized to\r\navoid
loading any additional async bundles on page load.\r\n\r\n![CleanShot
2024-11-06 at 10
51\r\n36@2x](https://github.com/user-attachments/assets/019c3c79-49b5-4e63-9b94-3d7b02963a9b)\r\n\r\n###
Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [x] This was checked for breaking
API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)","sha":"aa4f430ed59694b7f8c3d5b318c76e6aef95331e"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199029","number":199029,"mergeCommit":{"message":"[ML]
Data Visualizer: Optimize initial load bundles. (#199029)\n\n##
Summary\r\n\r\nPart of
https://github.com/elastic/kibana/issues/194171.\r\n\r\nThe
`dataVisualizer` plugin loads quite some bundle chunks on the
first\r\nKibana load. On `main` it currently looks like this on page
load:\r\n\r\n![CleanShot 2024-11-05 at 17
51\r\n35@2x](https://github.com/user-attachments/assets/7b2fcc7e-08fb-48b8-a1d9-03063b555e38)\r\n\r\nThis
PR refactors how embeddables and UI actions get initialized to\r\navoid
loading any additional async bundles on page load.\r\n\r\n![CleanShot
2024-11-06 at 10
51\r\n36@2x](https://github.com/user-attachments/assets/019c3c79-49b5-4e63-9b94-3d7b02963a9b)\r\n\r\n###
Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [x] This was checked for breaking
API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)","sha":"aa4f430ed59694b7f8c3d5b318c76e6aef95331e"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Walter Rafelsberger <walter.rafelsberger@elastic.co>
  • Loading branch information
kibanamachine and walterra authored Nov 11, 2024
1 parent f75f8ba commit 5d8a7d6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pageLoadAssetSize:
dataViewFieldEditor: 42021
dataViewManagement: 5300
dataViews: 65000
dataVisualizer: 27530
dataVisualizer: 30000
devTools: 38637
discover: 99999
discoverEnhanced: 42730
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,22 @@
* 2.0.
*/

import React from 'react';

import { i18n } from '@kbn/i18n';
import type { PresentationContainer } from '@kbn/presentation-containers';
import { tracksOverlays } from '@kbn/presentation-containers';
import type { EmbeddableApiContext } from '@kbn/presentation-publishing';
import type { UiActionsActionDefinition } from '@kbn/ui-actions-plugin/public';
import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
import type { CoreStart } from '@kbn/core-lifecycle-browser';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import React from 'react';
import { isDefined } from '@kbn/ml-is-defined';
import { COMMON_VISUALIZATION_GROUPING } from '@kbn/visualizations-plugin/public';
import { ENABLE_ESQL } from '@kbn/esql-utils';
import { FIELD_STATS_EMBEDDABLE_TYPE } from '../embeddables/field_stats/constants';

import type { DataVisualizerStartDependencies } from '../../common/types/data_visualizer_plugin';
import type {
FieldStatisticsTableEmbeddableApi,
FieldStatsControlsApi,
} from '../embeddables/field_stats/types';
import { FieldStatsInitializerViewType } from '../embeddables/grid_embeddable/types';
import type { FieldStatsInitialState } from '../embeddables/grid_embeddable/types';
import { getOrCreateDataViewByIndexPattern } from '../search_strategy/requests/get_data_view_by_index_pattern';
import { FieldStatisticsInitializer } from '../embeddables/field_stats/field_stats_initializer';

const parentApiIsCompatible = async (
parentApi: unknown
Expand Down Expand Up @@ -57,6 +50,21 @@ async function updatePanelFromFlyoutEdits({
initialState: FieldStatsInitialState;
fieldStatsControlsApi?: FieldStatsControlsApi;
}) {
const [
{ getOrCreateDataViewByIndexPattern },
{ FieldStatisticsInitializer },
{ tracksOverlays },
{ toMountPoint },
{ KibanaContextProvider },
{ isDefined },
] = await Promise.all([
import('../search_strategy/requests/get_data_view_by_index_pattern'),
import('../embeddables/field_stats/field_stats_initializer'),
import('@kbn/presentation-containers'),
import('@kbn/react-kibana-mount'),
import('@kbn/kibana-react-plugin/public'),
import('@kbn/ml-is-defined'),
]);
const parentApi = api.parentApi;
const overlayTracker = tracksOverlays(parentApi) ? parentApi : undefined;
const services = {
Expand Down Expand Up @@ -148,6 +156,16 @@ export function createAddFieldStatsTableAction(
);
},
async execute(context) {
const [
{ IncompatibleActionError },
{ FIELD_STATS_EMBEDDABLE_TYPE },
{ FieldStatsInitializerViewType },
] = await Promise.all([
import('@kbn/ui-actions-plugin/public'),
import('../embeddables/field_stats/constants'),
import('../embeddables/grid_embeddable/types'),
]);

const presentationContainerParent = await parentApiIsCompatible(context.embeddable);
if (!presentationContainerParent) throw new IncompatibleActionError();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
import type { CoreStart } from '@kbn/core-lifecycle-browser';
import type { UiActionsSetup } from '@kbn/ui-actions-plugin/public';
import type { DataVisualizerStartDependencies } from '../../common/types/data_visualizer_plugin';
import { createAddFieldStatsTableAction } from './create_field_stats_table';

export function registerDataVisualizerUiActions(
uiActions: UiActionsSetup,
coreStart: CoreStart,
pluginStart: DataVisualizerStartDependencies
) {
import('./create_field_stats_table').then(({ createAddFieldStatsTableAction }) => {
const addFieldStatsAction = createAddFieldStatsTableAction(coreStart, pluginStart);
uiActions.addTriggerAction('ADD_PANEL_TRIGGER', addFieldStatsAction);
});
const addFieldStatsAction = createAddFieldStatsTableAction(coreStart, pluginStart);
uiActions.addTriggerAction('ADD_PANEL_TRIGGER', addFieldStatsAction);
}

0 comments on commit 5d8a7d6

Please sign in to comment.