Performance issues compared to VDOM like React #2004
Replies: 1 comment
-
You should probably debounce the scroll events to the next animation frame, i.e. collect the scroll events into a signal and on the next animation frame, change the data for the latest scroll event. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When making a headless Datagrid for both React and Solid, I ran into something surprising: React is a lot smoother and more performant.
It looks like on scroll of the grid (i.e. when some properties change), unlike React which figures out what html nodes to update on a fine grained level, Solid instead re-creates every element.
Take a look at devtools flashing to show what elements are re-created on scroll:
React (nothing re-created):
https://github.com/solidjs/solid/assets/760314/fb84a76d-22ab-4225-b592-df49b74e4b8a
Solid (everything re-created each scroll event):
https://github.com/solidjs/solid/assets/760314/9095aa54-34ee-4410-b740-0ae441fb344d
I'm surprised as Solid is supposed to be performant and fine grained, but also I've only considered that granularity when dealing with single values.
These are the render loops of the grid:
https://github.com/Lightgrid-io/lightgrid/blob/master/packages/solid/src/components/DataGrid/DataGrid.tsx
The arrays are re-created on a change like a scroll event because properties in them change. For example columns and rows are virtualized so the items change as the user scrolls.
In React world this causes minimal changes to the DOM. But in Solid world this causes every element to get re-created.
Even on a filter change, which is designed specifically to cause as few renders as possible: the input state is local, and the
onChange
is just so the user can receive a callback and filter their data (debounced), causes an immediate loss of focus and re-rendering of the whole grid in Solid:First time: values disappears and input loses focus, on subsequent changes it strangely works
https://github.com/solidjs/solid/assets/760314/6f460632-0eef-4a56-a235-d1694b59a692
I thought perhaps swapping out
createSignal
withcreateStore
for some of these key objects would make a difference, but sadly it doesn't:I wonder if I'm doing something obviously wrong in the Solid paradigm? 🤔
If anyone is interested in going as far as trying it out:
pnpm dev
in packages/solid + react + docsBeta Was this translation helpful? Give feedback.
All reactions