Here’s a complete performance optimization strategy covering all three areas:
Chart Rendering Optimization: Switch to canvas-based rendering and implement batched updates. Replace your current approach:
const chartConfig = {
type: 'line',
options: {
animation: false,
elements: {line: {tension: 0}},
plugins: {decimation: {enabled: true, algorithm: 'lttb'}}
}
};
Disable animations for real-time charts - they’re unnecessary and consume CPU cycles. Use the LTTB (Largest Triangle Three Buckets) decimation algorithm which intelligently reduces points while preserving visual shape.
Data Windowing Techniques: Implement a sliding window buffer client-side:
class DataWindow {
constructor(maxSize = 300) {
this.buffer = [];
this.maxSize = maxSize;
}
add(point) {
this.buffer.push(point);
if (this.buffer.length > this.maxSize) this.buffer.shift();
}
}
For your 5-minute window, 300 points at 1-second intervals is sufficient. But I recommend aggregating to 5-second intervals (60 points total) - users won’t notice the difference visually.
Frontend Performance Tuning: Implement several optimizations:
- Batch Updates: Accumulate incoming data points and update charts every 500ms instead of on every message
- Virtual Scrolling: Only render charts in viewport using Intersection Observer API
- Web Workers: Offload data aggregation to a worker thread
- RequestAnimationFrame: Synchronize chart updates with browser repaint cycles
Implement batched updates:
let updateQueue = [];
streamAPI.subscribe('telemetry/all', (data) => {
updateQueue.push(data);
});
setInterval(() => {
if (updateQueue.length > 0) {
processAndRenderBatch(updateQueue);
updateQueue = [];
}
}, 500);
For 500+ devices, also implement device grouping - don’t show all devices simultaneously. Use tabs or expandable sections to limit visible charts to 10-15 at a time. This reduces the rendering workload dramatically.
Finally, consider using a specialized time-series visualization library like uPlot or Plotly which are optimized for high-frequency data streams. They handle large datasets much better than general-purpose charting libraries.
With these optimizations, you should handle 1000+ devices without lag.