model-viewers (5.7MB) causes other primitive components to "lag" across the page when scrolling
See original GitHub issueI’m using model-viewer
to display 1 model-viewer per card, and I have about 2-5 cards on the screen at any given time and about 11 models (5.7MB each) on the page total. Whenever I scroll down the page of cards, the models follow the scrolling fine (with low “latency”), and all of the other components, including the div
s that hold the models and the text within those div
s lag behind. What can be done to improve this experience?
P.S.
Even when the page is only showing one model (the others are visibility: hidden
), there is enough lag to be noticeable.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
model-viewers (5.7MB) causes other primitive components to "lag ...
Whenever I scroll down the page of cards, the models follow the scrolling fine (with low "latency"), and all of the other components,...
Read more >model-viewer issues and how to fix | GitAnswer
model-viewers (5.7MB) causes other primitive components to "lag" across the page when scrolling ... Pixel XL AR mode black screen iFrame - model-viewer ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@cdata Here ya go: https://model-viewer-mapbox-demo.herokuapp.com/
Alright, after a bit of poking, I think we uncovered the problem. It seems that the problem only occurs in Chrome (please let us know if you discovered this issue in other browsers).
Fundamentally, the problem is that the
<model-viewer>
elements are being rendered on the compositor, and their containers are not, so there is an async lag between the two as they paint.One potential fix for this is to force the container to be rendered on the compositor by forcing it onto a render layer. You can do this in Chrome by setting a CSS property like
will-change: transform
ortransform: translate3d(0, 0, 0)
on the container. For example, I was able to settransform: translate3d(0,0,0)
on<div class="demo-list">
and the lag in your demo disappears.Please be aware that while this will fix the problem, render layers allocate GPU memory, and if they are overused you will see bad effects from them on mobile devices and possibly even desktop browsers. I recommend using the “Layers” tab in Chrome dev tools to analyze the cost of the layers you have created.
Kudos go to @azakus for applying his deep well of web platform knowledge to this problem 🍻