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

Use one IntersectionObserver per viewport #153

Merged
merged 2 commits into from
Jul 27, 2018
Merged

Conversation

snewcomer
Copy link
Collaborator

This PR aims to use a service that utilizes IntersectionObserver's ability to observe multiple elements. Currently, we are instantiating a new IntersectionObserver per element on page. However, one optimization, especially in cases where many elements are beings watched (think advertisements or lazy loading hundreds of pictures), is simply use the same IntersectionObserver to watch multiple entries.

close #119

@snewcomer snewcomer self-assigned this Jul 22, 2018
@snewcomer snewcomer added WIP and removed WIP labels Jul 22, 2018
@snewcomer snewcomer changed the title Use on IntersectionObserver per viewport Use one IntersectionObserver per viewport Jul 23, 2018
* @property _observerOptions
* @default {}
*/
_observerOptions: {},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null / computed returning empty object / initialize on init. This could lead to leaking state between objects implementing this mixin.

@snewcomer
Copy link
Collaborator Author

@jheth Hey 👋 Was curious if you could try this out (only if you have a free moment though; otherwise, no worries) and lmk if it still works for ya. This does something similar we did for rAF, but for IntersectionObserver - i.e. a static administrator to reuse an observer.

@snewcomer
Copy link
Collaborator Author

Similar memory footprint for many use cases but if you have many different IntersectionObserver, then this should help slightly. Tested in a few different projects and all still seems well with the world.

Lmk if anybody experiences any issues.

@snewcomer snewcomer merged commit 2bc20d1 into master Jul 27, 2018
@snewcomer snewcomer deleted the enhancement/sn/one-io branch July 27, 2018 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate use of one Intersection Observer
2 participants