Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Will the DOM elements prebuild be a big performance concern? #263

Open
bfang711 opened this issue Feb 8, 2018 · 4 comments
Open

Will the DOM elements prebuild be a big performance concern? #263

bfang711 opened this issue Feb 8, 2018 · 4 comments

Comments

@bfang711
Copy link

bfang711 commented Feb 8, 2018

I know the number of total DOM elements upfront, so don't want to use infinite loading mode. However in the preparation for the DOM LONG list, one has to for-loop to generate all the DOM elements, although only several of them being actually rendered while the rest are clustered in a big blank DOM, according to the author of react-infinite. e.g. the sample code given in the manual.

  buildElements: function(start, end) {
        var elements = [];
        for (var i = start; i < end; i++) {
            elements.push(<ListItem key={i} num={i}/>)
        }
        return elements;
    },

I just wonder if the "for-loop" gonna be a performance concern if I have 1M elements in my list. Again, not related to rendering, but just this for-loop to reserve the DOM slots in the long list.

thank you

@bfang711
Copy link
Author

bfang711 commented Feb 8, 2018

I think this related to #138. I am looking for one that can reuse the DOM.
Now the question is that is it possible to give the number of items in the full list, and the elementHeight (which is fixed in my case) and calculate the total scrollable div height (not containerHeight), so that the scrollbar and the scroll can preset correctly without pre-generate all the DOMs.

thank you.

@joshribakoff
Copy link

joshribakoff commented Feb 10, 2018

If you have local state from which DOM nodes are generated, why not generate them asynchronously. On the infinite scroll callback, generate some DOM nodes on the fly "just in time", from your local state. If the user never scrolls down, you avoid wasting cycles rendering the DOM nodes they never see.

is it possible to give the number of items in the full list, and the elementHeight (which is fixed in my case) and calculate the total scrollable div height

Of course. Multiply. Am I missing something?

@bfang711
Copy link
Author

bfang711 commented Feb 10, 2018 via email

@joshribakoff
Copy link

If instantiating all your components is expensive then yes instantiate them in batches, during the onInfiniteLoad() callback. The whole promise of react-infinite is it will render only what is in the view. Usually instantiating a component is very cheap, its the render which is slow, which is why react-infinite was made.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants