-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Move projectChanged into HOC wrapping MenuBar, to avoid unnecessary renders #4676
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
Conversation
|
@mzgoddard Can you take a look at the failing menu bar tests? |
282d515 to
96cc18d
Compare
|
I think they were all linting issues. I'll see how the tests are tomorrow if its also failing units/integrations. |
Rendering the MenuBar does not depend on projectChanged. Some of its event handling does. Abstracting that dependency we can handle some behaviour in MenuBar without extra renders.
|
@benjiwheeler could you review this since you are working in a very similar area of code, and make sure that this approach could work with your change to the confirmation that you are working on? For context, this PR extracts the confirmation logic into an HOC (something I know you were considering) but for a different reason–adding the Additionally, it would also have the side benefit of making the logic for when to trigger a confirm more testable, since it extracts it from the menubar, like you were looking for. |
|
@paulkaplan Yes, I'll review. This is one of the approaches I've looked at for where to put |
|
Tested this, it does indeed seem to avoid unnecessary renders. It's not a huge difference in number of renders, because the boundary between It seems like this is a subset of the container-esque functions and state that should be pulled out of the |
benjiwheeler
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. See my comments above. This may not be the format we use long term -- we may want to move much more of the menu bar component into a container like this.
Resolves
Less time rendering on project change and unchange.
Proposed Changes
Move projectChanged out of MenuBar into a parent component and pass MenuBar a function to test what the projectChanged logic was doing.
Reason for Changes
MenuBar uses projectChanged in some event handling behaviour. So when projectChanged changes, MenuBar renders leading to its tree being reconsidered when the nothing has changed.
Another possible implementation would be use a shouldComponentUpdate lifecycle handle. I figured the approach in this PR would be more robust (create less bugs).
Benchmark Data
These values are the amount of time spent deserializing scratch blocks from an sb3 project (173918262). The change (%) doesn't represent this very well since its over deserializing a projects blocks, when the change specifically applies to the first block being deserialized.