4

I am trying to build an application with large json data and sending get request every 7 seconds. So, both data size and frequency are high. Should i use swr or axios with react hooks and setinterval. I am using ag-grid and react-vis chart to display data.

There are 12 tables in every page with 30-100 rows. I am concerned about the performance issues.

I'm new to react. I need some suggestions deciding the libraries.

Nitesh Tosniwal
  • 1,796
  • 2
  • 12
  • 17
Kumar
  • 51
  • 1
  • 3
  • 1
    I'm not familiar with `swr` but from a quick reading, seems like it's optimzed for such cases, so why prefer to it manually? You concern by right, it probably won't be the fastest app. There is a room for optimizations though (wsr probably do some of them), such as sending only diffs, not the all the data, if you have the time to deal with it. – Mosh Feu Dec 06 '20 at 09:13
  • thanks @MoshFeu. Is there any other ways to optimize for such applications with react? – Kumar Dec 06 '20 at 10:09
  • You can try to use websockets so if nothing changed in the server, the client won't do anything. Also, not to update all the UI at once (so every 3.5 seconds only half of the screen will change) – Mosh Feu Dec 06 '20 at 10:34
  • @MoshFeu thanks. but the backend does not use websockets, so this is the alternative. I am thinking about using angular instead of react, not sure if angular will give better performance. – Kumar Dec 06 '20 at 11:18

1 Answers1

4

The SWR library is more than just polling. One of its main functions is to provide a cache invalidation strategy. Besides, Request de-duplication, retry of exponential avoidance strategy, these functions are used out of the box, it is not recommended to implement it by yourself.

SWR first returns the data from cache (stale), then sends the fetch request (revalidate), and finally comes with the up-to-date data again.

It will give you a Real-time experience like WebSocket. Performance issues involve many aspects, using WebSocket may not be able to get good performance, you can try SWR

For more features, see features and performance

Lin Du
  • 88,126
  • 95
  • 281
  • 483