-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
When adding an item to an array (e.g. a todo list, adding a new Todo) it's advertised to do this (using the spread operator):
const [tasks, setTasks] = createSignal([])
const addTask = function() {
setTasks([...tasks(), { name: 'new task' }]);
}The problem with this is that it feels very wasteful - it's throwing away existing memory and then re-creating the array from scratch.
I'm new to solidjs so maybe it's my misunderstanding (I'm exploring switching from Vue, which doesn't re-create arrays you can simply push onto it, due to it being a Proxy).
I see there is a reconcile feature, but under the hood it looks like it's using https://github.com/solidjs/solid/blob/3d3207dd3aeb84c2a38377cf9f3b895995c2d969/packages/solid/store/src/modifiers.ts#L10 which re-creates the whole array in memory each time.
This isn't much of an issue with small arrays, but when dealing with super large arrays it's so wasteful to keep reconstructing that memory, garbage collection etc just to push one item onto it.
Is there a consideration for optimizing that in solidjs? Thank you for assistance! 😀