Skip to content

Performance ​

Values may refresh about 1 000 times per second, so functions used at each refresh must be cheap: no allocation in hot paths, precomputed tables, formatter objects cached. Every optimisation is measured against a naive baseline in benchmarks/ (pnpm bench), in Chromium through Playwright: the functions run where they run in the applications, with precise timers (the page is cross-origin isolated).

OperationLibraryBaselineGain
roundToFractionDigitsarithmeticNumber(formatDecimal())~41×
formatNumbercached Intl formatternew Intl.NumberFormat() per call~40×
formatDecimalcached Intl formatternew Intl.NumberFormat() per call~38×
roundToStepno float noiseMath.round(v / step) * step (noisy)0.5×

roundToStep is slower on purpose: it pays ~7 ns per call for exact results.

Generated from the JSDoc of the sources.