Fable.Solid icon indicating copy to clipboard operation
Fable.Solid copied to clipboard

Stack overflow when the model includes large lists (1k-2k elements)

Open lilnasy opened this issue 2 years ago • 4 comments

I am writing an entry for Fable.Solid Elmish in krausest/js-framework-benchmark. The benchmark involves creating, rendering, appending, updating, and deleting rows.

The implementation fails with the error below when the number of rows goes beyond 1k.

image I'm pretty sure application code is not at fault here; the update function returns control without any errors after adding over 1k elements to the model. You can see the full code here: App.fs

lilnasy avatar Jul 06 '23 04:07 lilnasy

Unrelated, but Ryan ran into your PR on stream and was amused.

AlexErrant avatar Jul 11 '23 17:07 AlexErrant

I was able to get this working with a few changes: https://github.com/krausest/js-framework-benchmark/compare/master...joprice:js-framework-benchmark:solidjs-elmish

  • switch from lists to arrays, which is hinted at in the Elmish.Solid file Attention: use arrays instead of lists for better performance
  • use anonymous records, which compile to plain js objects https://fable.io/docs/javascript/features.html#anonymous-records
  • avoid tuples - not sure about the runtime representation of tuples, but they were breaking reactivity until i switched to an anonymous records there as well

joprice avatar Jun 11 '24 02:06 joprice

Tuples are represented using arrays.

let a = "maxime", 32
export const a = ["maxime", 32];

MangelMaxime avatar Jun 11 '24 12:06 MangelMaxime

To track changes in an array, you would have to use a Foror Index component. Only functions and member expressions (=property access) are tracked when used in a reactive scope ( e.g. an effect or in JSX). That is why anonymous records work and tuples not.

(BTW I just updated the samples in this repo to use the latest version of solid-js)

goswinr avatar Jun 11 '24 13:06 goswinr