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

forEachCodeMirror is heavy when window resize on plenty of CodeMirror instance #5653

Closed
futurist opened this issue Nov 8, 2018 · 3 comments

Comments

@futurist
Copy link

futurist commented Nov 8, 2018

When there're plenty of CodeMirror instance in a document then window resize event will trigger below line:

https://github.com/codemirror/CodeMirror/blob/87702cf2eb53cabd25e4f994354ea9fc9e2c1d97/src/edit/global_events.js#L29

That is a heavy operation like the demo below (with 150+ CodeMirror cells):

not-ok

The chrome performance panel shows this:

image

Here you can compare with just 5 CodeMirror cells:

ok

Recommended to use some way to distribute the resize into frames like using below:

https://github.com/GoogleChromeLabs/idlize

marijnh added a commit that referenced this issue Nov 20, 2018
@marijnh
Copy link
Member

marijnh commented Nov 20, 2018

Attached patch should help a lot with this (by batching the updates to avoid all those relayouts)

@marijnh marijnh closed this as completed Nov 20, 2018
@futurist
Copy link
Author

futurist commented Dec 5, 2018

After tested with the patch, the performance is improved, but still have noticeable lag.

Can it be better for below?

  • for old browsers, keep it as is

  • for modern browsers, use modern way

  1. Before resize, check cell visibility, e.g. using
    https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API

  2. Only resize visible cells, keep others untouched

  3. When cell scroll into viewport, trigger a resize event to itself

Just a note for this issue, priority is very low....

@marijnh
Copy link
Member

marijnh commented Dec 5, 2018

This is more or less how CodeMirror 6 will work, but for 5 it's unlikely that visibility tracking will be added.

cone56 pushed a commit to cone56/CodeMirror that referenced this issue Jan 6, 2020
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