Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf #45

Open
bjoerge opened this issue Mar 5, 2018 · 8 comments
Open

Perf #45

bjoerge opened this issue Mar 5, 2018 · 8 comments

Comments

@bjoerge
Copy link

bjoerge commented Mar 5, 2018

Hi @clauderic, thanks for this library!

I'm having a few performance issues which seem to be caused by onScroll triggering a setState which triggers a re-render. Here's a capture of scrolling through a list with a renderItem that only render simple <span>Hi</span>-items:

image

For reference, this is using the dev build of React 15.6.1, with 6x CPU slowdown.

This can be improved by adding the scroll listener as a passive event listener instead of using onScroll (AFAIK React does not support specifying events as passive using on*-props, so it must be set up in componentDidMount).

Additionally, to increase performance even more the VirtualList component could support a debounce-prop, which takes a number of milliseconds to debounce the handleScroll method with.

Would you be interested in a PR for this?

@nicubarbaros
Copy link

That would be amazing @bjoerge, currently I am debouncing but still, I am seeing performance drops.

@bjoerge
Copy link
Author

bjoerge commented Mar 15, 2018

PR submitted: #47

@yogurt1
Copy link

yogurt1 commented May 19, 2018

What if use requestAnimationFrame?

componentDidMount() {
  let scrollTop = 0;
  const step = () => {
    if (scrollTop !== this.rootNode.scrollTop) {
      scrollTop = this.rootNode.scrollTop;
      this.handleScroll(scrollTop);
    }
    requestAnimationFrame(step);
  };
  this.rafId = requestAnimationFrame(step);
}

componentWillUnmount() { cancelAnimationFrame(this.rafId); }

react-sentinel as example

@damianobarbati
Copy link

Any tips to have a 60fps framerate when scrolling?

@ymaz
Copy link

ymaz commented Sep 12, 2018

what about to start using transform: translate3d instead of top?

@clauderic
Copy link
Owner

what about to start using transform: translate3d instead of top?

In my experience testing this, using transform was actually slower.

@ymaz
Copy link

ymaz commented Sep 13, 2018

@clauderic thanks! I'm just curious, in your perf test, did you use translate3d exact 3d option for transform or 2d (translatey)? From my understanding, translate3d should create one more virtual layer of context, which might help in terms of performance.
something like that

transform: translate3d(0px, %yourTopValue%px, 0px);

and change only %yourTopValue%?

@damianobarbati
Copy link

For anyone who may stumble on it: this will cause any position:fixed element inside to behave like a position:absolute relative to the transformed element.
Why worrying about it? Because in a current project of mine I have columns with truncated overflowing content (with ellipsis).
To show full content I use a fixed positioned tooltip on the column with the full content once hovering over the column.
I had to find out that the virtual table was using the transform and that's why it was not possible.

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

No branches or pull requests

6 participants