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

Pasting text while using markdownlint with a very large file can be slow (inconsistent, potential VS Code issue) #347

Open
gordykeene opened this issue Jul 21, 2024 · 8 comments

Comments

@gordykeene
Copy link

Type: Bug

  1. Enable markdownlint (v0.55.0)
  2. Open a large (~3.9MB) markdown file
  3. Paste a small text item (<100 chars) near the top of the file
    Observe a spinner appears while waiting for the paste to complete

(This is my first-ever bug report. VS Code opened this "Issue Reporter" that generated most of this content. I'm sorry if I missed any necessary details.)

Extension version: 0.55.0
VS Code version: Code 1.91.1 (f1e16e1e6214d7c44d078b1f0607b2388f29d729, 2024-07-09T22:06:49.809Z)
OS version: Windows_NT x64 10.0.22631
Modes:

System Info
Item Value
CPUs Intel(R) Core(TM) i9-14900 (32 x 1997)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 191.77GB (166.70GB free)
Process Argv --crash-reporter-id 8e915230-70c5-4f5f-99a1-d48334e3a594
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscoreces:30445986
vscod805:30301674
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
welcomedialogc:30910334
pythonnoceb:30805159
asynctok:30898717
pythonregdiag2:30936856
pythonmypyd1:30879173
2e7ec940:31000449
pythontbext0:30879054
accentitlementst:30995554
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
945dj816:31013170
pythoncenvpt:31062603
a69g1124:31058053
dvdeprecation:31068756
dwnewjupyter:31046869
impr_priority:31094925
wkspc-onlycs-c:31100201

@gordykeene
Copy link
Author

After reading other posts, it appears a profile is needed. I followed Profile the Running Extensions, reproduced the problem, and generated this file.

CPU-20240721T155235.067Z.cpuprofile.txt.zip

@DavidAnson
Copy link
Owner

To confirm: There is no delay for this scenario when you disable the markdownlint extension? The delay only happens when it is enabled?

I'll look at the trace soon and acknowledge some opportunities to improve performance, but will also call out that your scenario file seems unusually large and seems like an outlier.

Can you link to a copy of your file so I can try the scenario myself?

@gordykeene
Copy link
Author

Correct: When the markdownlint extension is disabled, there is no delay. Also, I have tried disabling all other extensions, leaving only markdownlint enabled, and the delay still occurs at least once out of every three paste attempts.

I agree that the file size is an outlier. As a daily log, it will only continue to grow, and being able to lint it is a huge help in keeping it meaningful and searchable (I do appreciate this extension!).

I can not provide the original file as sanitizing the PII would be time-consuming and risky, so I generated a similar file, which is attached. Using the generated file, I observe slowness while pasting text, although the time spent waiting on the spinner appears shorter (suggesting the issue is somehow content-related?).

lorem_ipsum_big.zip

@DavidAnson
Copy link
Owner

I've started looking at this. I see a delay maybe 1 of 5 times I paste that line. VS Code also gives me a lot of errors - even with markdownlint disabled - that look like this:

[Error - 9:28:35 PM] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Maximum call stack size exceeded
  Code: -32603 

That's not a good sign and leads me to believe the problem won't be some slow parsing logic in markdownlint or else it would be slow every time.

@DavidAnson
Copy link
Owner

I don’t think I’m going to be able to do much here. VS Code’s own telemetry suggests the slowdown is in its extensionHost process which is not surprising since it only happens when the markdownlint extension is running.

I disabled all event handlers except onDidChangeTextDocument, then wrapped its three phases in calls to time/timeEnd and tried copy/pasting that line from your sample file a few times.

Here’s a typical example of normal/fast behavior:

requestLint: 0.179931640625 ms
requestLint: 0.437ms
didChangeTextDocument: 1.72998046875 ms
didChangeTextDocument: 1.859ms
requestLint/setTimeout: 0.1572265625 ms
requestLint/setTimeout: 0.191ms

And here’s an example of spinner/slow behavior (captured just a moment after the above):

requestLint: 0.048095703125 ms
requestLint: 0.141ms
didChangeTextDocument: 0.5791015625 ms
didChangeTextDocument: 0.64ms
requestLint/setTimeout: 0.156005859375 ms
requestLint/setTimeout: 0.193ms

Note that the time spent executing markdownlint extension code is very similar - and actually faster for the slow scenario in all but one negligable case. This and the inconsistent repro and the VS Code stack size error above lead me to believe the delay is happening outside extension code that I control. I don’t have experience profiling VS Code itself and I’m not sure that’s the best use of my time.

I’ll leave this issue open for now, but I don’t currently think it’s actionable by me.

@DavidAnson DavidAnson changed the title Pasting text while using markdownlint can be slow Pasting text while using markdownlint with a very large file can be slow (inconsistent, potential VS Code issue) Jul 26, 2024
@gordykeene
Copy link
Author

Thank you for looking into it and following up. I completely understand why it's not actionable.

I appreciate your time. Do you have a "Buy Me A Coffee" or equivalent account?

@DavidAnson
Copy link
Owner

Hahaha, thanks, but you don't need to buy me a coffee for telling you I couldn't help. :)

That said, if you are feeling especially generous, there should be a sponsor button on the GitHub project page that goes here: https://github.com/sponsors/DavidAnson

@DavidAnson
Copy link
Owner

Thank you for the donation!!

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

No branches or pull requests

2 participants