Skip to content

Collection: Replace array spreads with native slice to fix GC stalls on massive datasets #9333

@tobiu

Description

@tobiu

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.

Metadata

Metadata

Assignees

Labels

aibugSomething isn't workingperformancePerformance improvements and optimizations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions