-
-
Notifications
You must be signed in to change notification settings - Fork 202
Collection: Replace array spreads with native slice to fix GC stalls on massive datasets #9333
Description
During "Turbo Mode" operations with massive datasets (e.g., 50k+ items), Neo.collection.Base utilizes the spread operator ([...array]) in several critical hot paths (initialization, filtering, sorting).
When a 50,000 item array is spread, it unpacks all references onto the JavaScript engine's call stack. This can exceed browser stack limits (causing crashes) and generates massive, instantaneous memory allocation spikes that force the Garbage Collector to stall the Main/App Worker thread.
In our DevIndex profiling, the first filter operation triggered three separate 50k spread operations in rapid succession (afterSetSourceId, doSort, and filter), causing a 3-second UI freeze.
Fix:
Replace all instances of [...largeArray] with largeArray.slice() within src/collection/Base.mjs. Array.prototype.slice() is a native C++ engine method that clones arrays directly in heap memory, completely bypassing the JS call stack and executing ~5x faster with significantly less GC thrashing.