Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SearchProfiler] Remove sources of recursion over potentially deeply nested objects #54015

Merged

Conversation

jloleysens
Copy link
Contributor

@jloleysens jloleysens commented Jan 6, 2020

Summary

Addresses this issue: #53989.

Please Note

  • most proposed changes are in fixtures (incl. formatting 🤦‍♂)
  • current issue exists on machines under low memory conditions.

Was not able to repro (yet), but found some areas that could be improved and risk of exceeding stack limits reduced (see steps taken).

In the original issue it looks like the stack limit is being exceeded due to a very large object being passed into immer. Because this is happening when View Details is being clicked it is most probably happening inside of the reducer.ts's use of produce.

Steps taken

  1. Create a limit for the recursively rendering component (x-pack/legacy/plugins/searchprofiler/public/np_ready/application/components/profile_tree/shard_details/shard_details_tree_node.tsx).
  2. Pass only required objects to produce in the store (e.g., remove the children property) Removed use of immer in non test code. Unfortunately the optimisations I proposed were not sufficiently addressing the issue :c
  3. Minor improvements to reduce the number of iterations and some checking logic
  4. Added basic test for reducer

Investigation

After meeting with @liza-mae and seeing the issue on her machine after the initial round of optimisations to deep object traversal (results of breakdown attribute coming from ES when profiling and the parent field we create), some of the "View Details" actions that were not working before were working, but the deeper elements still exceeded call stack limits. Because of this immer has been removed.

Removed recursive normalizeTimes functions (one fewer iteration through the entire data structure)
Optimizied appliation of tree mutations by taking `if` out of tight loop
Cleaned up types
@jloleysens jloleysens added v8.0.0 Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more release_note:skip Skip the PR/issue when compiling release notes Feature:Search Profiler v7.6.0 labels Jan 6, 2020
@jloleysens jloleysens requested a review from liza-mae January 6, 2020 14:28
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui (Team:Elasticsearch UI)

@jloleysens jloleysens requested review from sebelga and removed request for sebelga January 6, 2020 15:27
Copy link
Contributor

@liza-mae liza-mae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jloleysens for getting a fix for this issue so quickly! That's great! I tested your PR and looks like 'ConstantScoreQuery' is now working properly, however I am still seeing the issue with 'DocValuesFieldExistsQuery' field. I will attach a screenshot.

@liza-mae
Copy link
Contributor

liza-mae commented Jan 8, 2020

Seems like the field highlighted in below screenshot is still throwing a RangeError: Maximum call stack size exceeded.

Screenshot from 2020-01-07 19-52-31

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

@jloleysens jloleysens changed the title [SearchProfiler] Fix use of immer and other potential recursion issues [SearchProfiler] Remove sources of potential recursion over deeply nested objects Jan 9, 2020
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@liza-mae liza-mae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jloleysens I tested the latest commit and looks like all is passing now :) Yay!

@jloleysens jloleysens changed the title [SearchProfiler] Remove sources of potential recursion over deeply nested objects [SearchProfiler] Remove sources of recursion over potentially deeply nested objects Jan 10, 2020
@jloleysens jloleysens merged commit 753eb53 into elastic:master Jan 10, 2020
@jloleysens jloleysens deleted the fix/searchprofiler-max-stack-range branch January 10, 2020 09:56
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jan 10, 2020
…nested objects (elastic#54015)

* Added max tree depth guard
Removed recursive normalizeTimes functions (one fewer iteration through the entire data structure)
Optimizied appliation of tree mutations by taking `if` out of tight loop
Cleaned up types

* Tidy up data being passed into store (and through immer)

* Fix max tree depth logic

* Remove immer from non-test code.

Co-authored-by: Elastic Machine <[email protected]>
jloleysens added a commit that referenced this pull request Jan 10, 2020
…nested objects (#54015) (#54431)

* Added max tree depth guard
Removed recursive normalizeTimes functions (one fewer iteration through the entire data structure)
Optimizied appliation of tree mutations by taking `if` out of tight loop
Cleaned up types

* Tidy up data being passed into store (and through immer)

* Fix max tree depth logic

* Remove immer from non-test code.

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Search Profiler release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants