-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover] Improve data grid render performance (
flattenHit
and `fo…
…rmatHit`) (#192333) ## Summary This PR improves the performance of two important utilities used by Discover: `flattenHit` and `formatHit`. It may not have a big impact on typical Discover use cases, but these two functions can account for a significant portion of the Discover data grid render time when viewing documents with many fields (e.g. our `many_fields` performance journey) ### Improvements - `formatHit` - Used for formatting document column cell values - Previously we would call `formatFieldValue` on every field value in every document even though we only show up to a specific number of field values in each cell (configurable, but 200 by default), which can be very expensive in some cases. In this PR we only call `formatFieldValue` on field values that will be shown to the user, reducing the total calls from 343,850 to 10,000 for the `many_fields` dataset. - There are also some optimizations to the looping logic and much fewer allocations than before. - `ownKeys` (`flattenHit`) - Used to ensure document keys are consistently ordered when looping over them - We currently use a proxy around the `DataTableRecord.flattened` object to override the `ownKeys` function and ensure document keys are always consistently ordered when looping over them. The issue is that the sorting logic gets called every time `DataTableRecord.flattened` keys are looped over or accessed via `Object.keys`, `Object.entries`, etc., which happens often. In this PR the sorted keys are cached for each `DataTableRecord.flattened` instance until one of its properties are either set or deleted. - The actual sorting logic has also been optimized with less casting, removing calls to `localeCompare`, and caching. ### Tests 3 runs each, navigating to Discover with `many_fields` data. There's some overlap between `formatHit` and `ownKeys` since `formatHit` loops over `DataTableRecord.flattened` keys and triggers `ownKeys`, which is why the total render difference doesn't match the sum of differences for both methods. #### Main ||Total render|`formatHit`|`ownKeys` (`flattenHit`)| |---|---|---|---| ||4748 ms|1117 ms|1728 ms| ||4804 ms|1111 ms|1757 ms| ||4722 ms|1117 ms|1744 ms| |**AVG**|4758 ms|1115 ms|1743 ms| <img width="2168" alt="main" src="https://github.com/user-attachments/assets/dcd718fc-9da7-460d-a045-b88b23db5e1b"> #### This PR ||Total render|`formatHit`|`ownKeys` (`flattenHit`)| |---|---|---|---| ||3060 ms|159 ms|578 ms| ||3203 ms|154 ms|626 ms| ||3358 ms|160 ms| 623 ms| |**AVG**|3207 ms|158 ms|609 ms| <img width="2168" alt="pr" src="https://github.com/user-attachments/assets/c2c9df43-6b0b-426a-826d-231160e3f6ef"> #### Average differences |Total render|`formatHit`|`ownKeys` (`flattenHit`)| |---|---|---| |1551 ms|957 ms|1134 ms| ### Checklist - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- Loading branch information
1 parent
897cca0
commit 09af367
Showing
8 changed files
with
166 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters