vscode-markdown icon indicating copy to clipboard operation
vscode-markdown copied to clipboard

Enter and Backspace do not work or are very slow to respond

Open sahil48 opened this issue 4 years ago • 14 comments

Problem

What went wrong? I press backspace or enter. Nothing happened or would take 10 seconds to happen Expected behavior? a return key will be added or a previous letter deleted Your environment (if necessary)? Windows 10, VSCode 1.51.1

sahil48 avatar Nov 27 '20 14:11 sahil48

Please check the latest guide at

https://markdown-all-in-one.github.io/docs/contributing/performance-issue.html

Thank you.

Lemmingh avatar Nov 27 '20 17:11 Lemmingh

Personally, I guess you were working on a large file with thousands of lines.

Lemmingh avatar Nov 27 '20 17:11 Lemmingh

@sahil48 Thanks for the feedback and thank @Lemmingh for the debugging instructions.

Just want to say that we know it is frustrating to find the editor unresponsive. But most of the time, it is not our extension but the complex interaction between VS Code extensions that causes the problem. So please provide us more information to pinpoint the root cause.

Of course the CPU profile will tell us all the information. But you can also do a quick check before that: try again with all other extensions disabled (so we immediately know whether it is caused by other extensions).

image

yzhang-gh avatar Nov 27 '20 18:11 yzhang-gh

markdown-all-in-one.cpuprofile.txt

Hi there, I might be able to add a bit of context. I'm seeing the same performance issues (on backspace and enter) that get resolved when I turn off Markdown: All in One's onBackspace and onEnter functionality.

I've tried to take a CPU profile and attached it here. I'm just pressing enter on a checklist within a markdown file several times and seeing a lag every time I press enter. As for reproducing with a specific file, I'm not sure if I can provide a single file that will work, since the directory I'm reproducing in is quite large. However I see the issue if I have a directory of only about 5-10 md files.

If it's helpful, I'm using Markdown: All in One as a component of my foam workflow and only see the issue in files that have more than 2 links to other md files.

mickey-is-codin avatar Feb 04 '21 14:02 mickey-is-codin

@mickey-is-codin Thanks for the information.

I've checked the CPU profile and it looked like the "markdown-notes" extension caused the lag.

image

And the most time-consuming record for this extension is

image

yzhang-gh avatar Feb 04 '21 15:02 yzhang-gh

https://github.com/kortina/vscode-markdown-notes/blob/211ca0ac0f5fb89a9315da04ee7141e5e0ef6cf6/package-lock.json#L2040-L2049

Interesting, markdown-notes itself does not use markdown-it-regexp (seemingly the suspect) at all, but simply exposes @thomaskoppelaar/markdown-it-wikilinks, which is a dependent of the suspect, by extendMarkdownIt().

Then, both VS Code's MarkdownEngine and our MarkdownEngine may load it.

So, The author of @thomaskoppelaar/markdown-it-wikilinks might be able to explain why the even loop was blocked for such a long time.

Lemmingh avatar Feb 05 '21 10:02 Lemmingh

some addition to @mickey-is-codin post How to disable onBackpsace and onEnter functionality, to make Backspace and Enter keys more responsive.

Ctrl + Shift + P -> Open Keyboard Shortcuts -> find markdown.extension.onEnterKey or markdown.extension.onBackspaceKey -> Right Click -> Remove Keybinding.

Beware, that this will disable all Markdown-All-In-One functionality attached to this events. For example, if you disable onEnter hook, automatic list items creation will not work anymore.

heyzling avatar Sep 14 '21 14:09 heyzling

I'm having the same issue as OP. I tried the extension bisect, and markdown all in one was found to be the cause. I also tried removing the enter and backspace shortcut, which works but also removes valuable features of the extension.

Is this just a limitation of the tool, or will this be improved in the future?

BTW, the file I was working on is a 33k line file of markdown, so definitely a large file. All large files seem to do this.

miloofcroton avatar Oct 02 '21 22:10 miloofcroton

@miloofcroton Thanks for the feedback.

Those keys should work well (without any lag) in most cases. However, there can be complex interactions when there are several Markdown extensions working together (e.g., markdown-notes as above).

You can also record a CPU profile which can help us find out the root cause (instructions here).

yzhang-gh avatar Oct 03 '21 02:10 yzhang-gh

33k line

Large from the perspective of Markdown.

Even cmark can take tens to hundreds of milliseconds to process such thing. Besides, the last time I visited its repo, the test cases didn't exceed 100 000 lines and 500 000 code points per line. If 100k is supposed to be the extreme, 33k is already one third of it.

Our implementation currently makes use of markdown-it, regular expressions, and something else. So I feel 1 ~ 10 seconds is still reasonable for now when it's fed with tens of thousands of lines.


If I understand the parsing strategy correctly ...

If you register k kinds of block structures and have n lines of input (totally p code points), then, the complexity of block parsing will be at least O( k * n ), sometimes it can reach O( k * (n^2) ) or O( k * (p^2) ).

Within each block, if you register i kinds of inline structures and have c code points of input, then, the complexity of inline parsing will be at least O( i * c ), and I heard some syntax causes O( i * (c^2) ).

Adding constants, factors, and other details, we can produce a significant result.

Lemmingh avatar Oct 03 '21 13:10 Lemmingh

FYI I disabled Markdown All in One a while ago because it was really slow (several seconds) for a file of about 6k lines. I'm tracking this issue since then to reenable it if someone find the time/energy to fix it.

dorian-marchal avatar Oct 04 '21 16:10 dorian-marchal

After updating vscode 1.64.0, this problem occurs on my macOS 11, then I disable onBackpsace and onEnter functionality, it works fine.

Seems that 1.64.0 version update changes something to slow down extension further.

labuladong avatar Feb 07 '22 15:02 labuladong

Agree. Here it's in Ubuntu 20, also same problem after I updated to VSCode 1.67. Even if I disable all other plugins, the issue still exists.

platinhom avatar Feb 23 '22 10:02 platinhom

Seems that 1.64.0 version update changes something to slow down extension further.

I'm not sure, but https://github.com/microsoft/vscode/pull/140816 looks terrible. That is to say, the built-in vscode.markdown-language-features extension since VS Code 1.64 may have serious performance issues on large documents, slowing down the extension host and making ours unresponsive.

Lemmingh avatar Mar 08 '22 03:03 Lemmingh

I've got the same problem. Even new files are buggy. In my case, backspace & writing just after a backspace is laggy. The rest is slow but usable.

I've had this issue on macOS, Win10, Ubuntu WSL remote & Ubuntu 20.04

I've had this problem for a few months (if it isn't already a year now).

Sorry I don't have any further info to report.

Clovel avatar Sep 20 '22 16:09 Clovel