vscode-markdown
vscode-markdown copied to clipboard
Enter and Backspace do not work or are very slow to respond
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
Please check the latest guide at
https://markdown-all-in-one.github.io/docs/contributing/performance-issue.html
Thank you.
Personally, I guess you were working on a large file with thousands of lines.
@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).
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 Thanks for the information.
I've checked the CPU profile and it looked like the "markdown-notes" extension caused the lag.
And the most time-consuming record for this extension is
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.
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.
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 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).
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.
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.
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.
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.
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.
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.