A Million Points, One Cursor: Making Vibration Analysis Fast in the Browser
When an analyst drags a harmonic cursor across a vibration spectrum, the cursor should move with the mouse without lag. With over a million data points on screen, ours didn't. Here's how we fixed that, and what other teams can take from it. We built a unified condition-based monitoring (CBM) platform for one of our clients, which brings sensors from different OEMs onto one screen. Most factories don't buy all their sensors from one vendor, so this matters. It also means the data varies a lot. Some sensors sample slowly and some very fast. Some send short captures and some send long ones. For each reading, analysts look at two charts: the TWF (time waveform, the raw signal over time) and the FFT (the same signal broken into frequencies). They place harmonic and sideband cursors on the FFT to match peaks to machine faults. We show the TWF and FFT for all three measurement axes together: Axial (A), Vertical (V) and Horizontal (H). For example, imagine a sensor sampling at 24 kHz over a 10-second window: - TWF: 24,000 × 10 240,000 points per axis - FFT: N samples give N/2 frequency bins, so 120,000 points per axis (0.1 Hz resolution, up to 12 kHz) - Across all three axes: 720,000 TWF points + 360,000 FFT points ≈ 1.08 million points on screen Why not just downsample? We tried. ECharts, our charting library, has a built-in sampling option, and we set it to LTTB, a popular downsampling algorithm for charts. But the interactive tools, like cursors, hover and markers, started behaving inconsistently. The likely reason: with sampling on, the drawn line only goes through the points LTTB picked, and those picks change as you zoom. Our hover and markers still snapped to the real FFT bins, so what was drawn and what the tools pointed at could drift apart. Earlier experience had also shown us that downsampled data from some OEMs was missing important peaks, and for an analyst, a missing peak can mean a missed fault. So we chose to show every point as received. The result: marking harmonics on this much data was slow and laggy. TL;DR: Memoization, moving compute off the main thread with Web Workers (transferring buffers instead of cloning them), per-frame chart updates without React, binary search instead of linear scans, and virtualized lists. Before fixing anything, we set a target. A 60 Hz display shows a new frame every 16.6 ms, but your code doesn't get all of it. Google's RAIL performance model recommends finishing your own work in about 10 ms, because the browser needs the remaining 6 ms to draw the frame. On a 120 Hz display, the whole frame is only 8.3 ms. Our goal: once the data has loaded, no loading screens, no stutter, no lag. The "once loaded" part matters because the flow spans three screens: Point Overview → Spectrums Overview → Analysis. We load the data once and serve it from a cache for every later screen, annotation and report. So after the first load, navigating feels instant. The flame graph (a profiler view of where time goes) showed most of the time going into calculations. We derive a lot from the raw TWF on the frontend, such as unit conversions. Here's the core issue. In the browser, JavaScript runs on the main thread by default, and that same thread handles layout, painting and user input. While our math ran, the page couldn't respond: stutter, dropped frames, a cursor that lagged behind the mouse. So we moved the calculations to Web Workers, a browser API for running code on background threads. There's a catch. Sending data to a worker with postMessage copies it by default (the browser structured-clones it), and cloning hundreds of thousands of numbers can itself block the main thread. So for large payloads, we do one copy ourselves: the main thread packs the fetched numbers into Float64Arrays, each a compact block of raw memory, and then transfers their underlying buffers to the worker instead of cloning them: js A transfer doesn't copy the bytes. It moves ownership of the memory to the worker, and the main thre