mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
# Backport This will backport the following commits from `main` to `8.8`: - [[ResponseOps] optimize building ecsFieldMap (#159251)](https://github.com/elastic/kibana/pull/159251) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Patrick Mueller","email":"patrick.mueller@elastic.co"},"sourceCommit":{"committedDate":"2023-06-08T14:06:01Z","message":"[ResponseOps] optimize building ecsFieldMap (#159251)\n\nresolves https://github.com/elastic/kibana/issues/157772\r\n\r\nPreviously on my M1 Macbook, the `ecsFieldMap` constant takes about 170\r\nms to be created. It appears this is another case of `array::reduce()`\r\nand object spread causing performance issues.\r\n\r\nConverting to (essentially) a filter and map got the time down to 4 ms.\r\n\r\nSlightly critical even though this is only ever run once - because it's\r\nrun at startup time, and blocking everything else from running.\r\n\r\nSee:\r\n\r\n-\r\nhttps://www.richsnapp.com/article/2019/06-09-reduce-spread-anti-pattern\r\n-\r\nhttps://prateeksurana.me/blog/why-using-object-spread-with-reduce-bad-idea/","sha":"6e81ae83bc17b020684e3d206dbb696c225e9d1c","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Alerting","release_note:skip","Team:ResponseOps","v8.9.0","v8.8.2"],"number":159251,"url":"https://github.com/elastic/kibana/pull/159251","mergeCommit":{"message":"[ResponseOps] optimize building ecsFieldMap (#159251)\n\nresolves https://github.com/elastic/kibana/issues/157772\r\n\r\nPreviously on my M1 Macbook, the `ecsFieldMap` constant takes about 170\r\nms to be created. It appears this is another case of `array::reduce()`\r\nand object spread causing performance issues.\r\n\r\nConverting to (essentially) a filter and map got the time down to 4 ms.\r\n\r\nSlightly critical even though this is only ever run once - because it's\r\nrun at startup time, and blocking everything else from running.\r\n\r\nSee:\r\n\r\n-\r\nhttps://www.richsnapp.com/article/2019/06-09-reduce-spread-anti-pattern\r\n-\r\nhttps://prateeksurana.me/blog/why-using-object-spread-with-reduce-bad-idea/","sha":"6e81ae83bc17b020684e3d206dbb696c225e9d1c"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/159251","number":159251,"mergeCommit":{"message":"[ResponseOps] optimize building ecsFieldMap (#159251)\n\nresolves https://github.com/elastic/kibana/issues/157772\r\n\r\nPreviously on my M1 Macbook, the `ecsFieldMap` constant takes about 170\r\nms to be created. It appears this is another case of `array::reduce()`\r\nand object spread causing performance issues.\r\n\r\nConverting to (essentially) a filter and map got the time down to 4 ms.\r\n\r\nSlightly critical even though this is only ever run once - because it's\r\nrun at startup time, and blocking everything else from running.\r\n\r\nSee:\r\n\r\n-\r\nhttps://www.richsnapp.com/article/2019/06-09-reduce-spread-anti-pattern\r\n-\r\nhttps://prateeksurana.me/blog/why-using-object-spread-with-reduce-bad-idea/","sha":"6e81ae83bc17b020684e3d206dbb696c225e9d1c"}},{"branch":"8.8","label":"v8.8.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Patrick Mueller <patrick.mueller@elastic.co>
This commit is contained in:
parent
f3a3b6cbac
commit
57149aab96
1 changed files with 18 additions and 20 deletions
|
@ -11,25 +11,23 @@ import { EcsMetadata, FieldMap } from './types';
|
|||
|
||||
const EXCLUDED_TYPES = ['constant_keyword'];
|
||||
|
||||
export const ecsFieldMap: FieldMap = Object.keys(EcsFlat).reduce((acc, currKey) => {
|
||||
const value: EcsMetadata = EcsFlat[currKey as keyof typeof EcsFlat];
|
||||
|
||||
// Exclude excluded types
|
||||
if (EXCLUDED_TYPES.includes(value.type)) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
return {
|
||||
...acc,
|
||||
[currKey]: {
|
||||
type: value.type,
|
||||
array: value.normalize.includes('array'),
|
||||
required: !!value.required,
|
||||
...(value.scaling_factor ? { scaling_factor: value.scaling_factor } : {}),
|
||||
...(value.ignore_above ? { ignore_above: value.ignore_above } : {}),
|
||||
...(value.multi_fields ? { multi_fields: value.multi_fields } : {}),
|
||||
},
|
||||
};
|
||||
}, {});
|
||||
export const ecsFieldMap: FieldMap = Object.fromEntries(
|
||||
Object.entries(EcsFlat)
|
||||
.filter(([_, value]) => !EXCLUDED_TYPES.includes(value.type))
|
||||
.map(([key, _]) => {
|
||||
const value: EcsMetadata = EcsFlat[key as keyof typeof EcsFlat];
|
||||
return [
|
||||
key,
|
||||
{
|
||||
type: value.type,
|
||||
array: value.normalize.includes('array'),
|
||||
required: !!value.required,
|
||||
...(value.scaling_factor ? { scaling_factor: value.scaling_factor } : {}),
|
||||
...(value.ignore_above ? { ignore_above: value.ignore_above } : {}),
|
||||
...(value.multi_fields ? { multi_fields: value.multi_fields } : {}),
|
||||
},
|
||||
];
|
||||
})
|
||||
);
|
||||
|
||||
export type EcsFieldMap = typeof ecsFieldMap;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue