Slow performance on PageDown/PageUp

CodeMirror is very slow when using the keys PageDown/PageUp with a large editor. You notice this when having a long document loaded and keep PageDown pressed.

We found a solution in updating the endOperation function like:

export function endOperation(cm) {
  let op = cm.curOp
  requestAnimationFrame(() =>
    finishOperation(op, group => {
      for (let i = 0; i < group.ops.length; i++)
        group.ops[i].cm.curOp = null
      endOperations(group)
    })
  })
}

Is it safe to delay the finishOperation call?

No. Much current code is written with the assumption that operations finish synchronously.

How big a document are you testing with, and in which browser? In a 30 000 line document in Firefox I’m not seeing a noticeable lag when using pageup/down.

Document was around 20.000 lines, but the document size doesn’t seem to be the problem. With a small editor size it is fast, it gets slow when using the editor fullscreen.

How many visible lines do you have when the editor is fullscreen?

there are 70 lines visible

I can notice a slight lag in Chrome with that editor height. Firefox still seems snappy. So yeah, that’s unfortunate, but the work it’s doing is more or less necessary (repaint the lines that get scrolled into view when the user takes an action), and I don’t think it is realistic to change the operation model in the short term, so I’m afraid this is just something you’ll have to live with.

The lag is indeed with Chrome, we use it as code editor in a Node Webkit application which uses chromium for the rendering. I noticed the same delay in the Brackets editor.

Overall performance is good. With mouse scrollweel scrolling is fast, only noticed the slow performance with the PageDown/PageUp keys, probably because it also needs to update cursor position then.

Figured out it was the complex layout of the whole app that is causing the dom updates of codemirror being slow, when simplifying the layout it becomes a lot faster. Codemirror standalone on a page is super fast.

Thanks for the fast response, seems that this wasn’t really an issue in CodeMirror.

You could try adding a CSS rule like .CodeMirror { contain: strict; } and see if it helps.

1 Like