Skip to content

High CPU usage and lag during cursor positioning #1648

Closed

Description

@fxha

Description

NOTE: This is a release blocking issue for v0.16.x.

Mark Text becomes laggy when setting the cursor to another paragraph in larger documents.

Steps to reproduce

  1. Build latest develop version and load MARKDOWN_SYNTAX.md.
  2. The first lag should occur after the file was loaded.
  3. (Scroll a bit and) set cursor in some paragraph - short freeze/lag should occur.
  4. Set cursor to another paragraph - short freeze/lag should occur.
  5. Move the cursor in the same paragraph - no lag occurs.

Expected behavior:

No freezes/lags should occur.

Actual behavior:

Setting a cursor in another paragraph freezes the editor for a short time in larger documents. The behavior may depend on computer performance.

Link to an example: [optional]

12% CPU usage := 100% on one CPU core. In the both examples, I set cursor and directly type afterwards.

v0.16.0-testing:

mt_lag

v0.15.1:

mt_lag_v0 15 1

Versions

  • Mark Text: develop (dfc7390) due to numbered code block lines - that are currently disabled!
  • Operating system: all

Activity

  1. added
    🐛 bug
    🐞 pri/critical
    on Nov 7, 2019
  2. self-assigned this
    on Nov 7, 2019
  3. fxha commented on Nov 8, 2019

    @fxha
    ContributorAuthor

    Numbered code block lines are temporary disabled due to this issue.

    Stack Trance:

    mt_numered_code_block_overview

    mt_numbered_code_blocks

  4. Jocs commented on Nov 8, 2019

    @Jocs
    Member

    @fxha The Stack Trance above is at code line number enabled?

  5. fxha commented on Nov 8, 2019

    @fxha
    ContributorAuthor

    The Stack Trance above is at code line number enabled?

    Yes, that's right. There are to much Recalculate Style and tons of forced Layout operations. BTW setCursor is also a performance bottleneck because it consume twice as much time as the whole document rendering.

  6. Jocs commented on Nov 8, 2019

    @Jocs
    Member

    because it consume twice

    What do you mean twice here?

  7. fxha commented on Nov 8, 2019

    @fxha
    ContributorAuthor

    @Jocs I think I found another issue: we render a document twice when loading the first file using editor event bus and muya force render the whole document. This issue doesn't occur when closing the tab and open the file again in the same instance.

    mt_inital_rendering

    it consume twice

    What do you mean twice here?

    render takes ~180ms and setCursor ~420ms (Chromiums Recalculate Style take ~50s and Layout the remaining).

  8. added
    🚄 performance
    on Nov 8, 2019
  9. Jocs commented on Nov 21, 2019

    @Jocs
    Member

    @fxha I move this issue to project 0.17.0, and will not release the line number feature in v0.16.0.

  10. Jocs commented on Jun 27, 2026

    @Jocs
    Member

    Thank you for this detailed performance report. The editor engine has been completely rewritten since this was filed. In the new engine (@muyajs/core, now shipping): clicking between paragraphs no longer triggers a content re-render — the click handler defers via requestAnimationFrame and passes needUpdate=false to setCursor, so only the DOM Selection is updated. Code block line numbers are now reconciled O(delta) via ResizeObserver (which fires post-layout asynchronously), not on every cursor change. There is no longer a document-wide style recalculation on inter-paragraph cursor positioning. Closing as resolved by the engine migration.

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

Metadata

Metadata

Assignees

Labels

🐛 bug🐞 pri/critical🚄 performance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions