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

rstats is causing a full document layout on each update #2

Open
kirbysayshi opened this issue Jan 22, 2014 · 4 comments
Open

rstats is causing a full document layout on each update #2

kirbysayshi opened this issue Jan 22, 2014 · 4 comments
Assignees

Comments

@kirbysayshi
Copy link

On your example pages (as well as my own experiments), I'm seeing a full document layout in Chrome:

screenshot 2014-01-21 22 15 46

It's only taking around 0.5ms, but I still find it strange that rstats is forcing the entire document to relayout. And in terms of a single frame, that's almost 3% of the total time allotted for 60fps. Obviously rendering rstats is not free, but it should ideally use as little time as possible.

Thanks for making rstats, it's been really cool to use!

@kirbysayshi
Copy link
Author

Update:

Setting an explicit pixel height and overflow: hidden on the main wrapper div seems to limit the scope by setting a layout boundary. But the ideal would be to auto calculate that based on the counters/graphs. In addition, setting the text node of the span tags manually instead of using textContent could also prevent unnecessary layouts too (http://stackoverflow.com/questions/17199958/why-does-setting-textcontent-cause-layout-thrashing).

@ghost ghost assigned spite Jan 22, 2014
@spite
Copy link
Owner

spite commented Jan 29, 2014

Good points.

I've updated the lib so it fixes the full document layout (fixing overflow and setting height)
I still think there should be an easier way to fix it.

Regarding the textContent causing layout thrashing, I've tried several approaches, including the textNode.nodeValue, but there's no difference. I'll try a specific test case and see what I find.

@kirbysayshi
Copy link
Author

I also looked into setting textContext vs nodeValue and couldn't get chrome to report differently either. So I'm really hopeful you'll figure something out!

spite pushed a commit that referenced this issue Dec 18, 2015
@kirbysayshi
Copy link
Author

@spite So... nearly 10 years later! Today I discovered what was causing the layout thrashing, after recently including rstats in a new project.

text-align: right!!

The Chrome devtools > Rendering have a Layout Shift Regions checkbox.

image

It seems that whenever a number changes digits, whether it's 0 -> 0.0 or 0 -> 10, etc, text-align: right causes a layout shift! The fix is text-align: left.

Hope you're well!

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

2 participants