question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Huge performance issue when dispatching hundreds of actions

See original GitHub issue

On boot, the app I’m building gets a stream of data from a server. This stream can have hundreds of messages and entities and each message is handled separately.

It takes a tremendous amount of time to dispatch actions after UI has rendered, because every state change re-renders the @connected component.

I wrote a short example that shows dispatching 1000 actions before render (5-15ms) and 500 after render (~2.5s). So this is clearly not a redux issue.

https://jsbin.com/ruziwa/edit?js,console,output

Obviously component doesn’t need to re-render every single dispatched action, but re-rendering should be throttled (say, every 50ms). Is there an established approach for that or does it need to be integrated in @connect?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:10
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
eladocommented, Jan 21, 2016

Well, adding

ItemListContainer.prototype.render = _.throttle(ItemListContainer.prototype.render, 20)

really boosts performance.

Updated https://jsbin.com/ruziwa/11/edit?js,console,output

Probably messing with React’s methods is not the right approach though.

2reactions
esamattiscommented, Jan 21, 2016

Probably messing with React’s methods is not the right approach though.

Yeah that will break sooner or later…

pseudo code


var store = createStoreWithBatchMiddleware();
var messages = [];

stream.on("message", msg) => messages.push(msg));

setInterval(() => {
  messages.forEach(msg => store.dispach(handleMessage(msg)));
  messages = [];
}, 50);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Redux FAQ: Performance
Will dispatching many actions take up memory? Further information. Will caching remote data cause memory problems? Further information ...
Read more >
How is performance affected by the dispatching of numerous ...
Normally React batches in event handlers and effects, but not in async code. You can manually control this by using the batch api...
Read more >
React Redux: performance considerations when dispatching ...
In a React Redux app, what happens when you dispatch multiple actions in a row? When used out of the box without any...
Read more >
3 small tips for better Redux performance in a React app
3. Batch actions to reduce # of renders ... Whenever you have to chain multiple actions one after the other (which you intentionally...
Read more >
Redux FAQ: Performance
Will dispatching many actions take up memory? ... support dispatching arrays · React Redux #263: Huge performance issue when dispatching hundreds of actions....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found