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

Resolve redux devtools crashing #4484

Merged
merged 1 commit into from
Dec 21, 2020
Merged

Conversation

msorens
Copy link
Contributor

@msorens msorens commented Dec 15, 2020

🔩 Description: What code changed, and why?

Before this patch, ReduxDevTools in the browser (Chrome or Firefox) would crash very soon after launching the Automate UI. Sometimes it would actually mention that it was going to be slow and consume a huge amount of memory.

To see this: install the Redux Dev Tools browser extension, enable it, navigate to a2-dev.test in your browser, open the browser Dev Tools (cmd + opt + i), and open the Redux tab in the browser Dev Tools.

Depending on your timing, you might see an initial few actions like this...
image

... but it will stop updating and eventually crash.

You can see that it is consuming huge amounts of memory via Activity Monitor, htop, or other process monitor. In the illustration I have filtered by chrome's helpers and sorted descending. The topmost "Google Chrome Helper (Renderer)" before this patch is applied will quickly grow to just about 5 GB -- yes, gigabytes! -- and that is precisely when the Redux Dev Tools will report a crash.

image

The redux dev tools docs include a Troubleshooting Section on Excessive Memory Use. There it talks about introducing sanitizing the state and action against huge pieces with an action sanitizer and a state sanitizer: https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md#actionsanitizer--statesanitizer

I went down a couple false trails trying to unravel this: the first was hunting the ui-router aspect mentioned on the troubleshooting page.

The second was ngrx/router-store crashing Chrome Redux DevTools Extension (ngrx/platform#537). That may actually have been an issue in our code base at one time, but we already have the referenced code there integrated into ngrx.reducers.ts, so it is not involved in the current issue.

The path forward

There were two things I needed to figure out to resolve this issue:

What to prune

I needed to isolate the actions and state generating large data footprints in our data store, then prune those using action/state sanitizers.

Wiring up the sanitizers

The only references (e.g., https://github.com/zalmoxisus/redux-devtools-extension/#14-using-in-production) only show using sanitizers via createStore, which is not used directly in an Angular application.

This issue (zalmoxisus/redux-devtools-extension#455) -- which again discusses the not relevant ui-router problem -- goes as far as wiring them up to a thing called composeEnhancers... but then does not show what to do with that constant.

This article (https://medium.com/@zalmoxis/using-redux-devtools-in-production-4c5b56c5600f) ties together the createStore and the composeEnhancers, but alas, nothing further.

One more issue (zalmoxisus/redux-devtools-extension#619) discusses some possibilities but nothing concrete there.

I finally divined that I need to use the StoreDevtoolsModule...
image

... and, in fact, actionSanitizer and stateSanitizer are components of the StoreDevtoolsConfig.
image

⛓️ Related Resources

Because this was a non-trivial exercise, I pushed an update to their troubleshooting doc via this PR.

👍 Definition of Done

image

👟 How to Build and Test the Change

  • install the Redux Dev Tools browser extension
  • enable it
  • navigate to a2-dev.test in your browser
  • open the browser Dev Tools (cmd + opt + i)
  • open the Redux tab in the browser Dev Tools
  • navigate around the Automate app
  • observe the actions populating the store in the redux Dev Tools

✅ Checklist

📷 Screenshots, if applicable

Before crashing it sometimes complains it is going to be slow
and consume a huge amount of memory.
Needed to isolate the actions and state generating large data footprints
and prune those using action/state sanitizers.
That is described in the troubleshooting section of the docs.
As it took me some time to work through adapting the supplied info to
Automate, I pushed an update to their docs as well.

https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/Troubleshooting.md#excessive-use-of-memory-and-cpu

Signed-off-by: michael sorens <msorens@chef.io>
@msorens msorens added bug 🐛 Something isn't working ui automate-ui labels Dec 15, 2020
@msorens msorens self-assigned this Dec 15, 2020
@netlify
Copy link

netlify bot commented Dec 15, 2020

👷 Deploy preview for chef-automate processing.

🔨 Explore the source changes: 8e06064

🔍 Inspect the deploy logs: https://app.netlify.com/sites/chef-automate/deploys/5fd91ffe3e18c4000737d59e

Copy link
Contributor

@tarablack01 tarablack01 left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Copy link
Contributor

@SEAjamieD SEAjamieD left a comment

Choose a reason for hiding this comment

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

Fantastic work, @msorens! Thanks for fixing this incredibly important tool 🎉

@msorens msorens merged commit 9cefd68 into master Dec 21, 2020
@msorens msorens deleted the automate-4433/redux-devtools-fix branch December 21, 2020 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants