A graph that freezes while plotting
The broken version finds each incoming element’s index by scanning everything already plotted (findIndex inside the loop): quadratic work that blocks the main thread. The fix memoizes each element’s index in a Map as it is plotted, so every lookup is O(1): linear work, identical output.
How this is measured
Measured live on this device. Both versions get the same seeded records (about 6% repeat an earlier id) and produce the same plot; the time covers the plotting function only, not drawing. The record count comes from a quick calibration so the broken version takes about 1–2 s here, with a floor of 1,600. One run, so background activity in the browser can move the number.
The TRM Labs note below is a past production result, not measured here.
In production at TRM Labs: graph plot matching on 1,600 elements went from 15.5 s → 14 ms after a 20+ PR push I led.