Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] [Timeline] Consolidate reduces, remove unneeded a…
…sync/awaits, other small fixes (elastic#197168) ## Summary For most of 8.x, both anecdotally from users and in development, timeline search strategy based apis would often seem slower than the equivalent search in discover or elsewhere in kibana, and I have long suspected that this came from how the timeline sever code formatted the elasticsearch responses for use in the UI, and while working on something else, noticed even higher than normal occurrences in logs of "][http.server.Kibana] Event loop utilization for /internal/search/timelineSearchStrategy exceeded threshold of..." and so I tried to refactor all of the functions in place as much as possible, keeping the apis similar, most of the unit tests, etc, but removing as many as possible of the Promise.alls, reduce within reduce, etc. This has lead to a substantial improvement in performance, as you can see below, and with larger result sets, I think the difference would only be more noticeable. After fix: ~40 ms for formatTimelineData with ~1000 docs <img width="1470" alt="image" src="https://github.com/user-attachments/assets/c664f940-aa37-4335-9204-2a9300fbafa0"> Before fix: ~18000 ms for formatTimelineData with ~1000 docs <img width="1464" alt="image" src="https://github.com/user-attachments/assets/124fa327-13b9-41ef-9489-8d27f853590c"> [chrome_profile_timeline_slow.cpuprofile](https://github.com/user-attachments/files/17825602/chrome_profile_timeline_slow.cpuprofile) [chrome_profile_timeline_fast.cpuprofile](https://github.com/user-attachments/files/17825606/chrome_profile_timeline_fast.cpuprofile) I've attached the chrome devtools profiles for each, the time was measured with the function: ``` async function measureAwait<T>(promise: Promise<T>, label: string): Promise<T> { const start = performance.now(); try { const result = await promise; const duration = performance.now() - start; console.log(`${label} took ${duration}ms`); return result; } catch (error) { const duration = performance.now() - start; console.log(`${label} failed after ${duration}ms`); throw error; } } ``` Wrapped around the call to formatTimelineData in x-pack/plugins/timelines/server/search_strategy/timeline/factory/events/all/index.ts ### Checklist - [ ] [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
- Loading branch information