@@ -143,6 +143,13 @@ let _rxA_hi: Uint32Array = new Uint32Array(0);
143143let _rxB_hi : Uint32Array = new Uint32Array ( 0 ) ;
144144/** 256-bucket histogram reused every pass (never reallocated). */
145145const _rxCnt : Uint32Array = new Uint32Array ( 256 ) ;
146+ /** Pre-partition index buffers (grow lazily, never shrink). */
147+ let _finBuf : Uint32Array = new Uint32Array ( 0 ) ;
148+ let _nanBuf : Uint32Array = new Uint32Array ( 0 ) ;
149+ /** Sparse float values buffer; index = original row index (grow lazily). */
150+ let _fvals : Float64Array = new Float64Array ( 0 ) ;
151+ /** Uint32 view of _fvals.buffer; updated whenever _fvals is reallocated. */
152+ let _fvalsU32 : Uint32Array = new Uint32Array ( 0 ) ;
146153
147154// ─── SeriesOptions ────────────────────────────────────────────────────────────
148155
@@ -731,9 +738,15 @@ export class Series<T extends Scalar = Scalar> {
731738
732739 // Pre-partition NaN/null/undefined from finite values in one pass.
733740 // fvals stores numeric values by original row index (sparse: fvals[origIdx]).
734- const finBuf = new Uint32Array ( n ) ;
735- const nanBuf = new Uint32Array ( n ) ;
736- const fvals = new Float64Array ( n ) ;
741+ if ( _finBuf . length < n ) {
742+ _finBuf = new Uint32Array ( n ) ;
743+ _nanBuf = new Uint32Array ( n ) ;
744+ _fvals = new Float64Array ( n ) ;
745+ _fvalsU32 = new Uint32Array ( _fvals . buffer ) ;
746+ }
747+ const finBuf = _finBuf ;
748+ const nanBuf = _nanBuf ;
749+ const fvals = _fvals ;
737750 let finCount = 0 ;
738751 let nanCount = 0 ;
739752 let allNumeric = true ;
@@ -771,7 +784,7 @@ export class Series<T extends Scalar = Scalar> {
771784
772785 // fvals is a Float64Array; reinterpret its buffer as Uint32 to read raw bits.
773786 // On little-endian (x86/ARM): u32[2i] = lo 32 bits, u32[2i+1] = hi 32 bits.
774- const fvalsU32 = new Uint32Array ( fvals . buffer ) ;
787+ const fvalsU32 = _fvalsU32 ;
775788
776789 // Initialise ping arrays with identity indices and IEEE-754 sort keys.
777790 // Transform: positive floats → XOR sign bit; negative → XOR all bits.
0 commit comments