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

Add an "Optimization" recipe #1783

Closed
markerikson opened this issue May 30, 2016 · 21 comments
Closed

Add an "Optimization" recipe #1783

markerikson opened this issue May 30, 2016 · 21 comments
Labels

Comments

@markerikson
Copy link
Contributor

markerikson commented May 30, 2016

Per discussion in #1751 , it's time we added a recipes page to cover performance and optimization. @JAndritsch has volunteered to help write it, and I can definitely provide feedback and assistance.

Initial potential set of topics to cover per that discussion:

  1. Connect components to state at the lowest level possible to prevent cascading renders from parent to children.
  2. Normalize your data and pass collections of IDs instead of collections of large objects to components.
  3. Use ImmutableJS.
  4. Take advantage of "initialProps".
  5. Re-define shouldComponentUpdate() when necessary.
  6. Use React.addons.Perf to find and eliminate wasted renders.
  7. Use Chrome's built-in profiling tools.
  8. Memoization with Reselect
  9. Per-instance component memoization
  10. Performance in general. That subscriptions are O(n), that React Redux shallowly compares props, that memoization helps us avoid recalculations, etc.

Link-dumping a bunch of potential references, docs, and discussions:

@markerikson
Copy link
Contributor Author

@JAndritsch
Copy link

Thanks for putting this together, Mark. I should have some free time this week to start combing through those links and gathering info. I'll ping you once I have a rough draft.

@somebody32
Copy link
Contributor

Looks really good! I think that list is not in the final order of topics appearing in the guide?
And my 5 cents for now: I think it will be cool to add a topic about visualizing react component rerenders (with tools like render-visualizer). I know that this is more general to react perf, but for me, it was really helpful to find wrong container/representation hierarchy on lists

@markerikson
Copy link
Contributor Author

That was just the list of topics that @JAndritsch and @gaearon were proposing over in #1751 . Don't think any specific order was implied. And yeah, render visualization and such would be good to cover too.

@JisuPark
Copy link

Why don't we list the helpful tools for optimization?
In my case

also useful.

@JAndritsch
Copy link

Update: I've got a good start on this documentation and am continuing to work on it when time is available. I'll hopefully have a draft for review soon.

@markerikson
Copy link
Contributor Author

Cool, was going to ask if you'd had any time to look at it. I still haven't managed to start in on the "Structuring Reducers" page myself. Maybe this weekend, maybe?

Definitely ping me when you've got something to look at.

@HugoHeneault
Copy link

HugoHeneault commented Aug 8, 2016

Any updates on this, guys? :)

@cristian-sima
Copy link

cristian-sima commented Aug 10, 2016

@markerikson Can you give a code example for each of the 10 points?

Like a : do not do this, do this

@markerikson
Copy link
Contributor Author

@cristian-sima : I'm fairly busy at the moment, and when I do have time, my current priority is trying to work on the "Structuring Reducers" recipe described in #1784 . I'd suggest reading through the links listed, particularly the set of articles included in the "React Performance" part of my React links list (which is the first link mentioned in this issue).

@cristian-sima
Copy link

@markerikson How many connect functions do you think I should use?

My app is going slow, and I am using just 5 connects

@HugoHeneault
Copy link

@cristian-sima
Copy link

I have no idea what is that, but I will look :)

Thanks

@naw
Copy link
Contributor

naw commented Aug 11, 2016

@cristian-sima My experience is redux-devtools can slow things down quite a bit. If you are using redux-devtools, you might want to check how slow your app is without it before you get too far down the optimization road. You should be able to use substantially more than 5 connects.

@cristian-sima
Copy link

cristian-sima commented Aug 11, 2016

A significant improvement in performance I've made today by writing some shouldComponentUpdate.

Essentially, redux makes all the components to update. So, telling which to update has helped me

@markerikson
Copy link
Contributor Author

Hi, @JAndritsch . Wanted to check in and see if you are still planning to work on this. You said you'd started a draft - is it posted anywhere?

@JAndritsch
Copy link

Hey @markerikson.

Sorry for the delays here. Admittedly, I've had less time to work on this than originally thought. That being said, I still plan on putting in the effort when I can. I will send you the first draft when it's completed.

@markerikson
Copy link
Contributor Author

Gotcha. Yeah, I understand the "find time to write" issues :)

I'd actually suggest pushing up your work in progress to a fork repo now. That way we can help contribute as you go.

Thanks for helping with this!

@JAndritsch
Copy link

@markerikson Good idea. I created a separate branch and started the optimization recipe. Here's a direct link to it: https://github.com/JAndritsch/redux/blob/optimization-recipe/docs/recipes/Optimization.md.

@JAndritsch
Copy link

So I was just discussing Redux optimization today at work and that conversation reminded me about this thread. I'd still like to contribute, assuming the content is accurate. Would anyone here be interested in reviewing the draft above? If all looks well, I'll try to finish out the remaining sections and then submit a PR.

@markerikson
Copy link
Contributor Author

Yeah, I'll try to take a look at it over the next day or two.

On a related note, I wrote a blog post a couple months ago that discussed some of the major aspects of performance: Practical Redux, Part 6: Connected Lists, Forms, and Performance. Might be helpful to cross-reference some of the ideas in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants