How can I fix memory management and performance issues in my real-time dashboard using JS?

0
1
Asked By TechyRaccoon69 On

I'm working on a real-time dashboard that processes a ton of events over 1000+ per second through WebSocket. I'm sending this data to a Web Worker using SharedArrayBuffer for FFT processing, and then I draw the results on a canvas with requestAnimationFrame. Initially, everything runs smoothly, but after some time, the browser starts lagging, the RAM usage soars, and even when I shut down the WebSocket and the worker, the memory doesn't seem to recover. The canvas also fails to keep up with the incoming data. I've tried debouncing updates, utilizing OffscreenCanvas in the worker, and clearing the buffer manually, but profiling reveals a bunch of stuck requestAnimationFrame callbacks. What can I do to resolve this issue?

6 Answers

Answered By CanvasCritic42 On

I've dealt with performance issues while plotting with canvas as well, and I noticed that a lot of the bottleneck is related to the browser's rendering capabilities when it comes to drawing many line pixels. I downsample my plotting automatically, but still ended up with dropped frames. Depending on your needs, using a WebGL canvas could vastly improve the results. It's worth experimenting with, as I’ve seen better performance on that front.

Answered By CodeCraftedCat On

Check if each event is queuing its own requestAnimationFrame. It might be useful to create a pool for rAF calls where you manage a queue and trigger only one rAF at a time—this could reduce the lag by controlling how often the updates happen.

Answered By DataWhisperer22 On

You could cache the data from the last check and only send new data points to the web worker for processing. This should cut down on unnecessary processing and help the performance overall.

Answered By MemoryMaster98 On

It sounds like your requests are stacking up because they're being made at the wrong time. Try to limit those requests to only occur once a response has been fulfilled and the canvas has been updated. Think of it as comparing recursive timeouts versus intervals—only update when it's necessary.

Answered By PixelProwler87 On

One option to consider is using libraries like Phaser.js or Pixi.js for canvas updates. They might handle the rendering more efficiently. You also might want to think about implementing back-pressure in your application—decide if it's more important to process all data or to simply display the most recent changes. This could help manage the flow better.

Answered By RenderWizard75 On

Setting up a recursive requestAnimationFrame might help, too. This way, the function calls itself after every frame, allowing you to check for socket events and update accordingly within that loop. With the refresh rate of the browser, it should keep things moving smoothly; especially with thousands of updates per second.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.