[Investigations] - Improve useFieldBrowser performance#225859
[Investigations] - Improve useFieldBrowser performance#225859michaelolo24 merged 5 commits intoelastic:mainfrom
Conversation
e23f816 to
22fd768
Compare
01816ca to
030082b
Compare
|
Pinging @elastic/security-threat-hunting-investigations (Team:Threat Hunting:Investigations) |
6407cdd to
aa88062
Compare
| const { browserFields } = useMemo( | ||
| () => getDataViewStateFromIndexFields('', dataViewSpec.fields), | ||
| [dataViewSpec.fields] | ||
| () => browserFieldsManager.getBrowserFields(dataView, DataViewManagerScopeName.detections), |
There was a problem hiding this comment.
I feel like we should encourage developers to use the useBrowserFields hook instead of using the browserFieldsManager directly, unless there is a reason not to?
There was a problem hiding this comment.
I think we'll make sure a bit more required once we move all the content of the data_view_manager folder into a package, but I think we should start using the correct files now if we can?
There was a problem hiding this comment.
Yea, only problem is: useBrowserFields currently only properly works when the flag is on. useDataView doesn't return anything when the flag is off 😅 , so this would break everything. I'd rather not add custom logic to useBrowserFields, but can add a comment to these to replace them when the flag is defaulted on?
There was a problem hiding this comment.
Is it better to now add custom logic to useBrowserFields or to add logic that will have to be removed every where it's being used? 😄
aa88062 to
461fa85
Compare
PhilippeOberti
left a comment
There was a problem hiding this comment.
LGTM! Left a few non-blocker comments, mostly cleanup and somewhat subjective so feel free to ignore if you disagree with them :)
...c/attack_discovery/pages/results/attack_discovery_panel/tabs/alerts_tab/ai_for_soc/table.tsx
Outdated
Show resolved
Hide resolved
x-pack/solutions/security/plugins/security_solution/public/common/containers/source/index.tsx
Show resolved
Hide resolved
...ions/security/plugins/security_solution/public/data_view_manager/hooks/use_browser_fields.ts
Show resolved
Hide resolved
...ions/security/plugins/security_solution/public/data_view_manager/hooks/use_browser_fields.ts
Outdated
Show resolved
Hide resolved
.../plugins/security_solution/public/data_view_manager/utils/security_browser_fields_manager.ts
Show resolved
Hide resolved
.../plugins/security_solution/public/data_view_manager/utils/security_browser_fields_manager.ts
Show resolved
Hide resolved
.../plugins/security_solution/public/data_view_manager/utils/security_browser_fields_manager.ts
Show resolved
Hide resolved
461fa85 to
d2b9fa3
Compare
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Unknown metric groupsReferences to deprecated APIs
History
|
andrew-goldstein
left a comment
There was a problem hiding this comment.
Thanks for this improvement @michaelolo24 🙏
✅ Desk tested locally
LGTM 🚀
|
Starting backport for target branches: 8.19, 9.1 https://github.com/elastic/kibana/actions/runs/16127071487 |
|
Starting backport for target branches: 8.19, 9.1 https://github.com/elastic/kibana/actions/runs/16127075971 |
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
1 similar comment
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
## Summary This PR looks to improve the performance of the newly introduced `useBrowserFields` implementation. The currently used `DataViewSpec.fields` isn't performant at scale and is not cached. Existing code is as follows: [DataView.toSpec](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/data_view.ts#L147) call as seen [here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/abstract_data_views.ts#L391-L422), [here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/field_list.ts#L157-L159), and finally [here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/data_view_field.ts#L438-L440). While this may not be a significant issue at a few thousand fields, this does not scale well as the number of fields reaches the tens to hundreds of thousands. [Separate PR](elastic#225726) that moves away from spec usage to pure `DataView` usage The `useFieldsBrowser` hook is improved by relying directly on the DataView rather than the DataViewSpec. And there are improvements to the original sourcerer fieldBrowser calculation. Currently the use of `memoizeOne` doesn't actually work as the fields object passed to it is an object and not an array. A new fieldBrowserManager was introduced that caches based on the scope. Originally investigated caching via a `WeakMap` to avoid the scenario where all 4 (current) scopes cache the exact same DataView, but it looked like references to previously selected dataViews retained a strong reference in memory, which often led to all N number of selected dataViews being retained in the cache. The current approach is safer as the number of cached entries are capped at `DataViewManagerScopeName.length` ** Relevant configurations ** `xpack.securitySolution.enableExperimental: ['newDataViewPickerEnabled']` (cherry picked from commit 9a18757) # Conflicts: # x-pack/solutions/security/plugins/security_solution/public/cases/components/ai_for_soc/table.tsx
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
## Summary This PR looks to improve the performance of the newly introduced `useBrowserFields` implementation. The currently used `DataViewSpec.fields` isn't performant at scale and is not cached. Existing code is as follows: [DataView.toSpec](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/data_view.ts#L147) call as seen [here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/abstract_data_views.ts#L391-L422), [here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/field_list.ts#L157-L159), and finally [here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/data_view_field.ts#L438-L440). While this may not be a significant issue at a few thousand fields, this does not scale well as the number of fields reaches the tens to hundreds of thousands. [Separate PR](elastic#225726) that moves away from spec usage to pure `DataView` usage The `useFieldsBrowser` hook is improved by relying directly on the DataView rather than the DataViewSpec. And there are improvements to the original sourcerer fieldBrowser calculation. Currently the use of `memoizeOne` doesn't actually work as the fields object passed to it is an object and not an array. A new fieldBrowserManager was introduced that caches based on the scope. Originally investigated caching via a `WeakMap` to avoid the scenario where all 4 (current) scopes cache the exact same DataView, but it looked like references to previously selected dataViews retained a strong reference in memory, which often led to all N number of selected dataViews being retained in the cache. The current approach is safer as the number of cached entries are capped at `DataViewManagerScopeName.length` ** Relevant configurations ** `xpack.securitySolution.enableExperimental: ['newDataViewPickerEnabled']` (cherry picked from commit 9a18757) # Conflicts: # x-pack/solutions/security/plugins/security_solution/public/cases/components/ai_for_soc/table.tsx
|
Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync. |
|
Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync. |
… (#227009) # Backport This will backport the following commits from `main` to `8.19`: - [[Investigations] - Improve useFieldBrowser performance (#225859)](#225859) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Michael Olorunnisola","email":"michael.olorunnisola@elastic.co"},"sourceCommit":{"committedDate":"2025-07-07T20:23:14Z","message":"[Investigations] - Improve useFieldBrowser performance (#225859)\n\n## Summary\n\nThis PR looks to improve the performance of the newly introduced\n`useBrowserFields` implementation. The currently used\n`DataViewSpec.fields` isn't performant at scale and is not cached.\nExisting code is as follows:\n[DataView.toSpec](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/data_view.ts#L147)\ncall as seen\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/abstract_data_views.ts#L391-L422),\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/field_list.ts#L157-L159),\nand finally\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/data_view_field.ts#L438-L440).\nWhile this may not be a significant issue at a few thousand fields, this\ndoes not scale well as the number of fields reaches the tens to hundreds\nof thousands.\n\n[Separate PR](#225726) that moves\naway from spec usage to pure `DataView` usage\n\nThe `useFieldsBrowser` hook is improved by relying directly on the\nDataView rather than the DataViewSpec. And there are improvements to the\noriginal sourcerer fieldBrowser calculation. Currently the use of\n`memoizeOne` doesn't actually work as the fields object passed to it is\nan object and not an array.\n\nA new fieldBrowserManager was introduced that caches based on the scope.\nOriginally investigated caching via a `WeakMap` to avoid the scenario\nwhere all 4 (current) scopes cache the exact same DataView, but it\nlooked like references to previously selected dataViews retained a\nstrong reference in memory, which often led to all N number of selected\ndataViews being retained in the cache. The current approach is safer as\nthe number of cached entries are capped at\n`DataViewManagerScopeName.length`\n\n\n** Relevant configurations **\n`xpack.securitySolution.enableExperimental:\n['newDataViewPickerEnabled']`","sha":"9a18757162b038898f5dfb11f1aa3a1130ac749a","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Threat Hunting:Investigations","backport:version","v9.1.0","v8.19.0","v9.2.0"],"title":"[Investigations] - Improve useFieldBrowser performance","number":225859,"url":"https://github.com/elastic/kibana/pull/225859","mergeCommit":{"message":"[Investigations] - Improve useFieldBrowser performance (#225859)\n\n## Summary\n\nThis PR looks to improve the performance of the newly introduced\n`useBrowserFields` implementation. The currently used\n`DataViewSpec.fields` isn't performant at scale and is not cached.\nExisting code is as follows:\n[DataView.toSpec](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/data_view.ts#L147)\ncall as seen\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/abstract_data_views.ts#L391-L422),\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/field_list.ts#L157-L159),\nand finally\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/data_view_field.ts#L438-L440).\nWhile this may not be a significant issue at a few thousand fields, this\ndoes not scale well as the number of fields reaches the tens to hundreds\nof thousands.\n\n[Separate PR](#225726) that moves\naway from spec usage to pure `DataView` usage\n\nThe `useFieldsBrowser` hook is improved by relying directly on the\nDataView rather than the DataViewSpec. And there are improvements to the\noriginal sourcerer fieldBrowser calculation. Currently the use of\n`memoizeOne` doesn't actually work as the fields object passed to it is\nan object and not an array.\n\nA new fieldBrowserManager was introduced that caches based on the scope.\nOriginally investigated caching via a `WeakMap` to avoid the scenario\nwhere all 4 (current) scopes cache the exact same DataView, but it\nlooked like references to previously selected dataViews retained a\nstrong reference in memory, which often led to all N number of selected\ndataViews being retained in the cache. The current approach is safer as\nthe number of cached entries are capped at\n`DataViewManagerScopeName.length`\n\n\n** Relevant configurations **\n`xpack.securitySolution.enableExperimental:\n['newDataViewPickerEnabled']`","sha":"9a18757162b038898f5dfb11f1aa3a1130ac749a"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/225859","number":225859,"mergeCommit":{"message":"[Investigations] - Improve useFieldBrowser performance (#225859)\n\n## Summary\n\nThis PR looks to improve the performance of the newly introduced\n`useBrowserFields` implementation. The currently used\n`DataViewSpec.fields` isn't performant at scale and is not cached.\nExisting code is as follows:\n[DataView.toSpec](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/data_view.ts#L147)\ncall as seen\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/abstract_data_views.ts#L391-L422),\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/field_list.ts#L157-L159),\nand finally\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/data_view_field.ts#L438-L440).\nWhile this may not be a significant issue at a few thousand fields, this\ndoes not scale well as the number of fields reaches the tens to hundreds\nof thousands.\n\n[Separate PR](#225726) that moves\naway from spec usage to pure `DataView` usage\n\nThe `useFieldsBrowser` hook is improved by relying directly on the\nDataView rather than the DataViewSpec. And there are improvements to the\noriginal sourcerer fieldBrowser calculation. Currently the use of\n`memoizeOne` doesn't actually work as the fields object passed to it is\nan object and not an array.\n\nA new fieldBrowserManager was introduced that caches based on the scope.\nOriginally investigated caching via a `WeakMap` to avoid the scenario\nwhere all 4 (current) scopes cache the exact same DataView, but it\nlooked like references to previously selected dataViews retained a\nstrong reference in memory, which often led to all N number of selected\ndataViews being retained in the cache. The current approach is safer as\nthe number of cached entries are capped at\n`DataViewManagerScopeName.length`\n\n\n** Relevant configurations **\n`xpack.securitySolution.enableExperimental:\n['newDataViewPickerEnabled']`","sha":"9a18757162b038898f5dfb11f1aa3a1130ac749a"}}]}] BACKPORT-->
#227004) # Backport This will backport the following commits from `main` to `9.1`: - [[Investigations] - Improve useFieldBrowser performance (#225859)](#225859) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Michael Olorunnisola","email":"michael.olorunnisola@elastic.co"},"sourceCommit":{"committedDate":"2025-07-07T20:23:14Z","message":"[Investigations] - Improve useFieldBrowser performance (#225859)\n\n## Summary\n\nThis PR looks to improve the performance of the newly introduced\n`useBrowserFields` implementation. The currently used\n`DataViewSpec.fields` isn't performant at scale and is not cached.\nExisting code is as follows:\n[DataView.toSpec](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/data_view.ts#L147)\ncall as seen\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/abstract_data_views.ts#L391-L422),\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/field_list.ts#L157-L159),\nand finally\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/data_view_field.ts#L438-L440).\nWhile this may not be a significant issue at a few thousand fields, this\ndoes not scale well as the number of fields reaches the tens to hundreds\nof thousands.\n\n[Separate PR](#225726) that moves\naway from spec usage to pure `DataView` usage\n\nThe `useFieldsBrowser` hook is improved by relying directly on the\nDataView rather than the DataViewSpec. And there are improvements to the\noriginal sourcerer fieldBrowser calculation. Currently the use of\n`memoizeOne` doesn't actually work as the fields object passed to it is\nan object and not an array.\n\nA new fieldBrowserManager was introduced that caches based on the scope.\nOriginally investigated caching via a `WeakMap` to avoid the scenario\nwhere all 4 (current) scopes cache the exact same DataView, but it\nlooked like references to previously selected dataViews retained a\nstrong reference in memory, which often led to all N number of selected\ndataViews being retained in the cache. The current approach is safer as\nthe number of cached entries are capped at\n`DataViewManagerScopeName.length`\n\n\n** Relevant configurations **\n`xpack.securitySolution.enableExperimental:\n['newDataViewPickerEnabled']`","sha":"9a18757162b038898f5dfb11f1aa3a1130ac749a","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Threat Hunting:Investigations","backport:version","v9.1.0","v8.19.0","v9.2.0"],"title":"[Investigations] - Improve useFieldBrowser performance","number":225859,"url":"https://github.com/elastic/kibana/pull/225859","mergeCommit":{"message":"[Investigations] - Improve useFieldBrowser performance (#225859)\n\n## Summary\n\nThis PR looks to improve the performance of the newly introduced\n`useBrowserFields` implementation. The currently used\n`DataViewSpec.fields` isn't performant at scale and is not cached.\nExisting code is as follows:\n[DataView.toSpec](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/data_view.ts#L147)\ncall as seen\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/abstract_data_views.ts#L391-L422),\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/field_list.ts#L157-L159),\nand finally\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/data_view_field.ts#L438-L440).\nWhile this may not be a significant issue at a few thousand fields, this\ndoes not scale well as the number of fields reaches the tens to hundreds\nof thousands.\n\n[Separate PR](#225726) that moves\naway from spec usage to pure `DataView` usage\n\nThe `useFieldsBrowser` hook is improved by relying directly on the\nDataView rather than the DataViewSpec. And there are improvements to the\noriginal sourcerer fieldBrowser calculation. Currently the use of\n`memoizeOne` doesn't actually work as the fields object passed to it is\nan object and not an array.\n\nA new fieldBrowserManager was introduced that caches based on the scope.\nOriginally investigated caching via a `WeakMap` to avoid the scenario\nwhere all 4 (current) scopes cache the exact same DataView, but it\nlooked like references to previously selected dataViews retained a\nstrong reference in memory, which often led to all N number of selected\ndataViews being retained in the cache. The current approach is safer as\nthe number of cached entries are capped at\n`DataViewManagerScopeName.length`\n\n\n** Relevant configurations **\n`xpack.securitySolution.enableExperimental:\n['newDataViewPickerEnabled']`","sha":"9a18757162b038898f5dfb11f1aa3a1130ac749a"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/225859","number":225859,"mergeCommit":{"message":"[Investigations] - Improve useFieldBrowser performance (#225859)\n\n## Summary\n\nThis PR looks to improve the performance of the newly introduced\n`useBrowserFields` implementation. The currently used\n`DataViewSpec.fields` isn't performant at scale and is not cached.\nExisting code is as follows:\n[DataView.toSpec](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/data_view.ts#L147)\ncall as seen\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/abstract_data_views.ts#L391-L422),\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/field_list.ts#L157-L159),\nand finally\n[here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/data_view_field.ts#L438-L440).\nWhile this may not be a significant issue at a few thousand fields, this\ndoes not scale well as the number of fields reaches the tens to hundreds\nof thousands.\n\n[Separate PR](#225726) that moves\naway from spec usage to pure `DataView` usage\n\nThe `useFieldsBrowser` hook is improved by relying directly on the\nDataView rather than the DataViewSpec. And there are improvements to the\noriginal sourcerer fieldBrowser calculation. Currently the use of\n`memoizeOne` doesn't actually work as the fields object passed to it is\nan object and not an array.\n\nA new fieldBrowserManager was introduced that caches based on the scope.\nOriginally investigated caching via a `WeakMap` to avoid the scenario\nwhere all 4 (current) scopes cache the exact same DataView, but it\nlooked like references to previously selected dataViews retained a\nstrong reference in memory, which often led to all N number of selected\ndataViews being retained in the cache. The current approach is safer as\nthe number of cached entries are capped at\n`DataViewManagerScopeName.length`\n\n\n** Relevant configurations **\n`xpack.securitySolution.enableExperimental:\n['newDataViewPickerEnabled']`","sha":"9a18757162b038898f5dfb11f1aa3a1130ac749a"}}]}] BACKPORT-->
## Summary This PR looks to improve the performance of the newly introduced `useBrowserFields` implementation. The currently used `DataViewSpec.fields` isn't performant at scale and is not cached. Existing code is as follows: [DataView.toSpec](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/data_view.ts#L147) call as seen [here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/data_views/abstract_data_views.ts#L391-L422), [here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/field_list.ts#L157-L159), and finally [here](https://github.com/elastic/kibana/blob/27183690142a5590b4ad72d060c43cad869f3f3c/src/platform/plugins/shared/data_views/common/fields/data_view_field.ts#L438-L440). While this may not be a significant issue at a few thousand fields, this does not scale well as the number of fields reaches the tens to hundreds of thousands. [Separate PR](elastic#225726) that moves away from spec usage to pure `DataView` usage The `useFieldsBrowser` hook is improved by relying directly on the DataView rather than the DataViewSpec. And there are improvements to the original sourcerer fieldBrowser calculation. Currently the use of `memoizeOne` doesn't actually work as the fields object passed to it is an object and not an array. A new fieldBrowserManager was introduced that caches based on the scope. Originally investigated caching via a `WeakMap` to avoid the scenario where all 4 (current) scopes cache the exact same DataView, but it looked like references to previously selected dataViews retained a strong reference in memory, which often led to all N number of selected dataViews being retained in the cache. The current approach is safer as the number of cached entries are capped at `DataViewManagerScopeName.length` ** Relevant configurations ** `xpack.securitySolution.enableExperimental: ['newDataViewPickerEnabled']`
Summary
This PR looks to improve the performance of the newly introduced
useBrowserFieldsimplementation. The currently usedDataViewSpec.fieldsisn't performant at scale and is not cached. Existing code is as follows: DataView.toSpec call as seen here, here, and finally here. While this may not be a significant issue at a few thousand fields, this does not scale well as the number of fields reaches the tens to hundreds of thousands.Separate PR that moves away from spec usage to pure
DataViewusageThe
useFieldsBrowserhook is improved by relying directly on the DataView rather than the DataViewSpec. And there are improvements to the original sourcerer fieldBrowser calculation. Currently the use ofmemoizeOnedoesn't actually work as the fields object passed to it is an object and not an array.A new fieldBrowserManager was introduced that caches based on the scope. Originally investigated caching via a
WeakMapto avoid the scenario where all 4 (current) scopes cache the exact same DataView, but it looked like references to previously selected dataViews retained a strong reference in memory, which often led to all N number of selected dataViews being retained in the cache. The current approach is safer as the number of cached entries are capped atDataViewManagerScopeName.length** Relevant configurations **
xpack.securitySolution.enableExperimental: ['newDataViewPickerEnabled']