Skip to content

Mark Text performance improvement #511

Closed

Description

@fxha

Description

At the moment Mark Text using a simple String to represent the document content. When it comes to larger documents, this is very inefficient and result in high CPU and RAM usage because we create many copies from the String.

A solution would be to use a (immutable) data structure with support for snapshots (undo/redo) and better memory management. I don't want to go into the detail, but the explanation from Juan Pedro Bolivar Puente of his talk "Postmodern immutable data structures" or Atom's/vscode's blog post, does indeed. There are already libraries, which we can use like Superstring from the Atom text editor.

Problems

  • How do we interact with CodeMirror and the virtual HTML DOM stuff. Should we fork/implement this by our own and consider this problem?
  • Can we "just" change your API to use a different data structure?

Note to self: Atom has written a blog post about integrating Superstring with a virtual DOM.

Existing implementations

References

Activity

  1. added
    🦁 need discuss
    on Oct 16, 2018
  2. Jocs commented on Oct 17, 2018

    @Jocs
    Member

    @fxha Very comprehensive finishing work, I have recently considered refactoring some of the code in muya, such as the new document object model, new data management, which was previously unified into blocks. It will be divided into document object model and data management in the future. This will better support the undo and redo features, and one goal is to support collaborative editing.

  3. Jocs commented on Oct 17, 2018

    @Jocs
    Member

    How do we interact with CodeMirror and the virtual HTML DOM stuff. Should we fork/implement this by our own and consider this problem?

    �I maybe replace CodeMirror with other highlight code library, such as highlight.js and prism. Because CodeMirror has a large size. It is also possible for us to do DOM operations ourselves, so as to avoid repeated rendering.

    Can we "just" change your API to use a different data structure?

    Maybe it's not that simple. I've also looked at some open source libraries recently to see how they manage state and support collaborative editing. Such as quill, prosemirror and so on.

  4. added
    🚄 performance
    on May 19, 2019
  5. VegaDeftwing commented on May 24, 2019

    @VegaDeftwing

    Using Marktext 0.14.0-3 -- marktext-bin in the AUR on a very high end system

    Wanted to drop by and note that this is actually affecting real world use cases. I'm working on a massive markdown document over at https://github.com/VegaDeftwing/opinionatedeng/blob/master/opinionatedeng.md and hoboy does marktext get laggy, but then again so does everything else. Even just a raw text editor, like VSCode, with syntax highlighting for the markdown just gets bogged down.

    I haven't dug though the code at all so I'm not sure if these are done already or the feasibility/practicality of any of these recommendations but:

    • If images are rendered at all times, maybe only rendering them when on screen would help
    • Adding the option to disable some of the more advanced options (Vega Chart, Flow Chart, Sequence Diagrams) may help
    • As noted about history, anything with the clipboard is awful, and from the original issue description above, it does sound like this just comes down to the data structure used. You may be able to abuse some things about the data though. For example, it's almost certain that any document large enough to notice a performance impact will be organized by headings, maybe you could split at each header? I'm not sure this is a logical route to take, but I think it's worth considering
    • Similarly, the data is fundamentally raw text data and working with the MD file directly may be the obvious route, but there's no reason a cache where the file is converted to something more processing friendly couldn't be kept: say in JSON somewhere?

    I know that many of these suggestions hit the same issue as described above- a significant refactor is necessary no matter what, even if just switching to a better data structure as originally suggested.

    Thanks for all the great work on this project :)

    EDIT: just checked the roadmap and saw that it's at the top and already well planned out. Thanks again to everyone working so hard on this!

  6. sgon00 commented on May 29, 2020

    @sgon00

    I am a new user and filed many issues within two days. Today, I edited a file wihch has 1229 lines. I never thought that was a big file because other electron markdown editors have no problem of it. But until now, when I edit it in marktext, marktext just can't handle it. Every single char typing will result in 100% of CPU core. This makes marktext kinda not useable.

  7. brainchild0 commented on Jun 16, 2020

    @brainchild0
    Contributor

    I've also looked at some open source libraries recently to see how they manage state and support collaborative editing. Such as quill, prosemirror and so on.

    What is the relationship between Mark Text (Muya) and ProseMirror? ProseMirror seems to attempt to provide an elegant and robust solution to many of the low-level problems, such as document tree and revisions, separate from the presentation layer. Might Muya use ProseMirror underneath, in order to avoid separate development of the overlapping functionality? Might such an approach have added benefits (for example, interactivity with others servers using ProseMirror but not necessarily using Muya)?

  8. tmairegasnighto commented on Nov 29, 2020

    @tmairegasnighto

    I did some comparison testing on some large markup file (200kb). Between Typora, Marktext, Joplin, and Zettlr (the later two editing and viewing the rendered markup), Marktext seems to be about in the middle, with Typora really having the best (though still not great) performance. Though these are not apples-to-apples comparisons because they aren't all WYSIWYG editors. Microsoft Word's performance, as a comparison, is near-instant even on much larger files - although it's unknown how they achieve that.

  9. bigshans commented on May 18, 2022

    @bigshans
    Contributor

    Source Code Mode is much slower than WYSIWYG mode.

  10. kud commented on Apr 17, 2023

    @kud

    Mark Text is quite slow/not smooth, I don't know why, and I'm currently using a M1 cpu. It's the only app which is not smooth like that.

    Could be great to improve performance. Let me know if I can help. Thanks.

  11. Jocs commented on Jun 26, 2026

    @Jocs
    Member

    The architectural change requested here has been fully implemented in the new @muyajs/core editor engine (now shipping). The document is no longer represented as a flat string — it is a JSON block tree (TState[]) with all mutations tracked as ot-json1 operational transforms. Undo/redo is backed by op inversion rather than string snapshots, and rendering uses snabbdom virtual DOM diffing. This resolves the core performance and memory concerns raised in 2018. Closing as resolved by the engine migration.

  12. VegaDeftwing commented on Jun 26, 2026

    @VegaDeftwing

    Congrats on the rework! 8 years later is wild to see an issue get closed. I see the repos been using a lot of Claude lately, I take it that's been going well? I'm sorta mixed on AI, but seeing it have the real world impact of assisting FOSS projects in improving performance is really cool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🦁 need discuss🚄 performance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions