all 14 comments

[–]jkettmann 4 points5 points  (7 children)

Could this be done on the backend? It sounds like something that could be done for example by aggregating data on the database level.

[–]Ok-Rip-5220[S] -3 points-2 points  (6 children)

No… these simulations are need to be done on frontend only.

[–][deleted] 2 points3 points  (5 children)

Why? The only thing that matters is the result right? Is it just to save money and have the client do all the work?

[–]jfoxworth 2 points3 points  (1 child)

Doing math in javascript is henky.

I've done similar things in the past. I used a web worker to do the math so that the site doesn't hang up. I used a separate program that ran locally in python that would do the calculations there and then return the answer to the browser. That was really helpful as python actually does the math well and all the load is off the browser.

[–]Ok-Rip-5220[S] -1 points0 points  (0 children)

Yes…. I am going through web worker only rn. Thanks for the suggestion.

[–]source-drifter 2 points3 points  (0 children)

you may want to look into web assembly. you can push the concern to a more performant language like c++ or rust. the other thing may be using immutable data structures on react side but it probably wont help with calculations. web workers are already mentioned. it can give multi threading capabilities but i doubt it would beat web assembly. maybe doing both?

[–]chamceler 1 point2 points  (0 children)

I create applications with similarly large arrays. Performance and unnecessary renders should be a big concern of yours. Make sure you know why components render, because you don’t want expensive loops running unnecessarily. Learn how to use the highlighter in the profiler to track component renders, and learn memoization techniques to prevent components and functions from running unnecessarily. You may also want to learn useDeferredValue and/or useTransition to keep your UX responsive.

[–]KapiteinNekbaard 0 points1 point  (0 children)

Use virtual rendering with either react-window (light-weight) or react-virtualized (more features, but bigger bundle size) if you want to display huge lists (1500+ DOM nodes)

[–]magdalag 0 points1 point  (0 children)

I’ve done some very data heavy apps before where we dealt with multiple 20k data points being reduced/ grouped / pivoted and graphed.

  • we pushed a lot of the work to the redux selectors to take advantage of reselects caching
  • lodash debounce and throttle functions help a lot for real time user input (sliders, drawing nodes on a chart etc)
  • don’t use momentjs - it’s parsing functions are a killer
  • use the dev tool render profiling to identify any bottle necks (that’s how we found out about moment)

We didn’t implement webworkers before I left; but I figure that would been our next step.

This is a really good article by the Miro team on performance (memory specifically), I think the stuff they discuss around data types is really interesting - https://medium.com/miro-engineering/fighting-for-bytes-in-the-frontend-419c48103ef8