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

Make isVisible 10% faster by avoiding unneeded getComputedStyle() calls #287

Open
erikrose opened this issue May 21, 2021 · 2 comments · May be fixed by #288
Open

Make isVisible 10% faster by avoiding unneeded getComputedStyle() calls #287

erikrose opened this issue May 21, 2021 · 2 comments · May be fixed by #288

Comments

@erikrose
Copy link
Contributor

Emilio had a great idea. See this mail thread.

--

Err, yeah, I of course wanted to say "not visible".

If the node is zero size but has overflow, and you care about that, then you can check !element.getClientRects().length as the check instead.

-- Emilio

On 2/2/21 22:44, Erik Rose wrote:

Although, now that I think about it, what if a node's style.overflow is "visible"? Won't your suggested code call a node invisible even though its content can be seen? If so, I'm afraid the shortcut doesn't avail, because we have to go get the computed style to tell what the overflow property is, as we do around

if (elementRect.width === 0 && elementRect.height === 0 && elementStyle.overflow !== 'hidden') {
if (elementRect.width === 0 && elementRect.height === 0 && elementStyle.overflow !== 'hidden') {
. Hoping I'm wrong. :-)
Erik
Big help, potentially! I'll ticket it to try and benchmark. Did you really mean "return true", or did you mean "false" (meaning "not visible")?

Thanks!
Erik

On Jan 19, 2021, at 14:28 , Emilio Cobos Álvarez <[email protected] mailto:[email protected]> wrote:

~10% of the profile is under ResolveStyleLazily. That means that you're calling getComputedStyle in a display: none subtree.

Perhaps a bit counter-intuitively, I think you can basically eliminate that by checking something like:

let rect = ancestor.getBoundingClientRect();
if (rect.width == 0 || rect.height == 0)
return true;

That will also allow you to fix the style.{width,height} == '0' checks, which are bogus (it should use '0px'), and which can be removed with the snippet I posted above.

Hope it helps.

@RhnSharma
Copy link

I would like to take this one.

@RhnSharma RhnSharma linked a pull request May 23, 2021 that will close this issue
@afif1400
Copy link

I would like to work on this.

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

Successfully merging a pull request may close this issue.

3 participants