Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor lags badly when note contains many triple backtick blocks #7867

Closed
nickrbogdanov opened this issue Mar 3, 2023 · 10 comments
Closed
Labels
bug It's a bug desktop All desktop platforms high High priority issues

Comments

@nickrbogdanov
Copy link

I have a note that's about 1500 lines long, which has 50+ "```" preformatted blocks containing code, log snippets, and other miscellaneous data. I noticed that as this note grew, editing performance got worse and worse. For instance, just typing a few characters on a fresh line, then highlighting them and deleting them, took 8+ seconds. This is a problem on macOS and on Linux.

I opened up Help -> Toggle development tools, started Profiling, and reproduced the problem. It pointed to compileLanguage() in highlight.js as the culprit. Apparently, letting highlight.js autodetect the syntax highlighting scheme requires compiling or evaluating a massive number of regular expressions.

A simple repro case is to paste 1000 instances of a simple preformatted text block into a note, and then try adding/deleting text from the note:

image

As a workaround: when I disable syntax highlighting on each block, the performance issue goes away:

image

This may be similar to #1649

@nickrbogdanov nickrbogdanov added the bug It's a bug label Mar 3, 2023
@laurent22 laurent22 added desktop All desktop platforms high High priority issues labels Mar 3, 2023
@melsonic
Copy link
Contributor

melsonic commented Mar 4, 2023

@nickrbogdanov can you comment the version of Joplin that you are using?

@nickrbogdanov
Copy link
Author

nickrbogdanov commented Mar 5, 2023

I just reproduced the problem on Linux using the test case above. That version is:

image

It's from the Ubuntu snap, which looks to be a few months old: https://snapcraft.io/joplin-desktop

I also see it on macOS:

Joplin 2.9.17 (prod, darwin)

Client ID: 40b8b886d4c4461b8eedb5e2cd83e6b8
Sync Version: 3
Profile Version: 41
Keychain Supported: Yes

Revision: a84a8e7

If I navigate to Joplin -> Check for updates..., it tells me I'm on the latest release.

@melsonic
Copy link
Contributor

melsonic commented Mar 7, 2023

I just reproduced the problem on Linux using the test case above. That version is:

image

It's from the Ubuntu snap, which looks to be a few months old: https://snapcraft.io/joplin-desktop

I also see it on macOS:

Joplin 2.9.17 (prod, darwin)

Client ID: 40b8b886d4c4461b8eedb5e2cd83e6b8
Sync Version: 3
Profile Version: 41
Keychain Supported: Yes

Revision: a84a8e7

If I navigate to Joplin -> Check for updates..., it tells me I'm on the latest release.

I have 5 code blocks of 2367 lines of each but editor is working file, I agree that scrolling becomes a bit slow but it is understandable. I also tried it with 50 code blocks containing ~130 lines each.

here is the jopling version details that am using

Joplin 2.9.17 (prod, linux)

Sync Version: 3
Profile Version: 41
Keychain Supported: No

Revision: a84a8e771

@nickrbogdanov
Copy link
Author

@melsonic
Copy link
Contributor

melsonic commented Mar 7, 2023

Could you please try pasting my test case into a new note: https://gist.githubusercontent.com/nickrbogdanov/2da682ea0620dfbd137df8927d5834b7/raw/76f913b04fe0b31a26c27a90958a8bc064627e83/gistfile1.txt

Okay, just tried and found editing text becomes lazy, but it is also understandable. And on the other hand, It would be a rare case where a note will contain 1000 code blocks. That's because it will also be harder to navigate across such a large note.
@laurent22 do you have anything to suggest here?

@nickrbogdanov
Copy link
Author

Two things:

  1. This is just an easy repro case for the issue. I saw the same lag in a much smaller note, which is why I profiled it and came up with this repro case so you could see the same issue I'm seeing.

  2. The problem is not that the note contains 1000 code blocks. The problem is the syntax autodetection. If you override autodetection, the lag goes away: https://gist.github.com/nickrbogdanov/c086be9b511db63a68b34d6f7e713dbb

@laurent22
Copy link
Owner

Thanks @nickrbogdanov, that's good to know it's related to syntax autodetection, it might mean we can fix it by caching something

@laurent22
Copy link
Owner

laurent22 commented Mar 7, 2023

Well about 4 years ago I've implemented an optimisation to fix that exact problem, but somehow it disappeared over the years after multiple refactorings. I've enabled it again and it seems to work as expected (went from taking 2000ms to render on my machine to 20ms)

@nickrbogdanov
Copy link
Author

Hi, any chance this could be merged into the next 2.10.x release? Looks like it is in the dev branch but not the release-2.10 branch.

@laurent22
Copy link
Owner

No sorry, I would prefer if it goes through a prerelease in case there's any bug we didn't expect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It's a bug desktop All desktop platforms high High priority issues
Projects
None yet
Development

No branches or pull requests

3 participants