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 opacity instead of visibility for cursor blink animation #37

Closed
wants to merge 1 commit into from

Conversation

hubgit
Copy link
Contributor

@hubgit hubgit commented Jul 4, 2022

Clicking inside the editor on https://codemirror.net/ causes the cursor blink animation to start, which uses ~2% CPU and ~60/120 style recalculations per second (according to the Performance Monitor tab in Chrome's Dev Tools, in macOS).

Changing the animation from visibility: hidden to opacity: 0 reduces both of these measurements to approximately zero.

Caveat: I'm not sure whether this has any important effects on accessibility.

@marijnh
Copy link
Member

marijnh commented Jul 4, 2022

How are you measuring this? It seems odd that browsers would do so badly at optimizing visibility animation while not having the same issue with opacity.

@hubgit
Copy link
Contributor Author

hubgit commented Jul 4, 2022

I'm measuring by looking at the Performance Monitor tab in Chrome's Dev Tools while having the cursor focused in the editor.

visibility:hidden:
visibility

opacity:0:
opacity

@marijnh
Copy link
Member

marijnh commented Jul 5, 2022

I don't think this impacts accessibility. I'm generally wary of patches addressing specific issues in browsers like this, since those change all the time, but this seems harmless enough, and Firefox seems unimpacted, so I guess we can make this change.

marijnh pushed a commit that referenced this pull request Jul 5, 2022
Providing a slight optimization on Chrome.

Issue #37
@marijnh
Copy link
Member

marijnh commented Jul 5, 2022

Merged as e149f4b

@marijnh marijnh closed this Jul 5, 2022
@timdown
Copy link
Contributor

timdown commented Jul 5, 2022

I would assume that the difference is that visibility has the potential to affect layout while opacity doesn't.

@marijnh
Copy link
Member

marijnh commented Jul 5, 2022

How, though? Unlike display: none, visiblity: hidden elements take up room as normal, just aren't drawn.

@timdown
Copy link
Contributor

timdown commented Jul 5, 2022

Yeah, true, although not for all values of visibility, e.g collapse. I don't know. Probably not a helpful contribution of mine, sorry.

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