Fastest replace range option?

So i try to or have to replace a lot of specific ranges. And it just takes to long so the browser times out multiple times or crashes.

Basically i’m doing:
Editor.codeMirror?.getDoc().replaceRange(NewText, { line: i, ch: 0 }, { line: i, ch: OldText.length });

i also tried to buffer all my ranges in an array of range objects and use the operation method like this:
updates.forEach((update) => {
Editor.codeMirror?.replaceRange(update.text, update.from, update.to);
});

Well both just takes way to long. Are there more/faster options? It does not need to be instantly but would be nice to not trigger multiple timeouts/or atleast not crashing completeley

Have you tried wrapping the calls in an operation? That might help.