elm-infinite-list-view icon indicating copy to clipboard operation
elm-infinite-list-view copied to clipboard

Optimization: Only update the model when you scroll enough to change the skipCount

Open Herteby opened this issue 5 years ago • 1 comments

When scrolling, instead of updating on every scroll event/animationFrame, you could save a lot of rerenders by only doing it when it actually changes the skipCount. You can even add "chunking" so that it only updates every third row for example.

Example from my own virtual-list implementation:

 on "scroll"
    (Decode.map2
        (\scrollTop clientHeight ->
            { offset = floor scrollTop // itemHeight // chunkSize
            , containerHeight = floor clientHeight
            }
        )
        (Decode.at [ "target", "scrollTop" ] Decode.float)
        (Decode.at [ "target", "clientHeight" ] Decode.float)
        |> Decode.andThen
            (\newState ->
                if newState == state then
                    Decode.fail "No difference, ignore"
    
                else
                    Decode.succeed (onScroll newState)
            )
    )

https://gist.github.com/Herteby/ef0a9b4d688a216d9ebdc6968c9a0907

Herteby avatar Nov 19 '19 03:11 Herteby

Nice :) Would you mind creating a PR? :)

FabienHenon avatar Nov 19 '19 07:11 FabienHenon