Freeze and/or crash on long lines. #990

Closed
remcoros opened this Issue Nov 21, 2012 · 3 comments

Projects

None yet

2 participants

@remcoros

CodeMirror (v3 from github source) freezes (and sometimes crashes IE) on very long lines.

I use codemirror to format and highlight code. Sometimes, all this code is on one line.

When that happens, CodeMirror freezes for up to 10 seconds (on my i7/ssd/16gb ram gig) and sometimes crashes IE.

I debugged it into 'measureLineInner' (line 864). where it tries to loop trough every character of that line (in my case a +2500 char line).

Can this logic be optimized?

edit: IE 10 btw.
edit2: IE9 too

for now, I 'fixed' it by adding lineWrapping = true to the options. But this is not really what I want.

@marijnh
Member
marijnh commented Nov 22, 2012

I can reproduce this -- but only in IE. It appears that calling getBoundingClientRect (or accessing offsetTop/offsetLeft) causes a recomputation of the layout (or some other ridiculously expensive operation) every single time it is called. This amounts to about 1.6 milliseconds per character, which does really add up on long lines. Turning on text wrapping does indeed miraculously speed it up, but only by a factor four or so, so the problem is still noticeable.

This doesn't seem to happen for all nodes. If I use a node in a simple document, IE seems to properly cache the result and the whole thing speeds up by a factor 1000. So now the question is what it is about the CodeMirror DOM nodes that breaks caching.

@marijnh
Member
marijnh commented Nov 26, 2012

Please try with the attached patch. The situation still isn't great -- typing will be noticeably laggy on long lines -- but a lot better than the original situation where it would simply lock up.

This is the best I've been able to squeeze out of IEs crummy rendering engine for now. Ideas for further techniques to improve this are welcome.

@marijnh marijnh closed this Nov 26, 2012
@remcoros

Verified, that works (a bit better :-))

@marijnh marijnh added a commit that referenced this issue Dec 10, 2012
@marijnh marijnh Disable line measuring subdivision hack (#990) on IE7
It completely screws up bounding rects when this is enabled.
9dd6275
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment