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

Performance issues with folding

Open iandol opened this issue 3 years ago • 11 comments

Using VSCode 1.63.3, MATLAB 2021b on macOS 12.1 I am having many performance problems. I have disabled all my extensions except this one. I have lintOnSave set to false, and have tried providing or commenting out the mlint path. Every time I save the Process Explorer shows extension host go up to 100% CPU and saving takes a couple of seconds for a MATLAB classdef ~1500 lines log. It is as if lint on save is still activated? General performance slows down too with extension host often hitting 100%. Disabling the extension and everything goes back to normal... Is there a way to fully disable linting?

iandol avatar Jan 22 '22 17:01 iandol

I have the same problem @iandol (MacBook Pro with M1 chip Pro, macOS 12.1, MATLAB version 2021b)

haolimin01 avatar Jan 24 '22 04:01 haolimin01

I was having similar issues and I think it's related to code folding. Try switching the VSCode setting to 'indent' (or similar, cannot see VSCode, so the setting name might be slightly off).

gohma231 avatar Feb 04 '22 15:02 gohma231

Indeed, disabling editor.folding makes Code much faster to save and use way less CPU with MATLAB code. The setting you refer to is "editor.foldingStrategy": "indentation" which also improves performance (the default value is auto which uses language-specific setting or falls back to indentation). I also tried the new setting in 1.64, "editor.foldingMaximumRegions": 500, but this didn't help... So there is something in the folding code for the extension that is triggering this crazy CPU use...

iandol avatar Feb 04 '22 18:02 iandol

@Gimly should we kill the folding provider for this one? I feel like iterating across 10000s of tokens in a 1500 line file is not really something that'd be easy to optimize in any circumstance. The only real way to fix it is for VS Code to offer access to the document's tokens, so that it and all the other providers work faster anyway.

ghost avatar Feb 11 '22 15:02 ghost

Folding code in question is here:

https://github.com/SNDST00M/vscode-textmate-languageservice/blob/v0.2.1/src/foldingProvider.ts

ghost avatar Feb 11 '22 15:02 ghost

Okay so I've figured out the problem. 😳🙈

https://github.com/SNDST00M/vscode-textmate-languageservice/blob/v0.2.1/src/foldingProvider.ts#L97-L107

This is a loop algorithm that determines the line of the terminating token in the foldable. However, it does not terminate when the fold is completed and continues to loop until EOF token.

If there are 20 folds that's >20 loops til EOF with potentially thousands of superfluous tokens. Etc.

I was focused on researching browser support but I'll pause that and putt out an urgent fix for this ASAP

ghost avatar Mar 17 '22 20:03 ghost

@iandol could you rename the issue to add the word "folding"? Just for context

ghost avatar Mar 19 '22 12:03 ghost

@SNDST00M — done, thanks so much for all your hard work!!! I haven’t had a chance to test this as I am travelling, is it fixed?

iandol avatar Mar 19 '22 22:03 iandol

Honestly.. not entirely. The folding provider computes document outline a 2nd time in order to get headers and fold them.

https://github.com/SNDST00M/vscode-textmate-languageservice/blob/v0.2.2/src/foldingProvider.ts#L64-L68

Shoddy dev-wise and not performant on the user side. Ideally the tokens remain as a source-of-all-truth and I could just look for header tokens in there directly :)

ghost avatar Mar 23 '22 22:03 ghost

Hey there!

Just chiming in to confirm that using "editor.foldingStrategy": "indentation" indeed seems to help. I'm sitting here with a huge project, and with the auto setting, my editor is barely useable.

I would suggest pinning this issue, to make it easier for people to notice this workaround.

LeCyberDucky avatar Apr 05 '22 07:04 LeCyberDucky

The latest version of the service has significant folding perf improvements, you can test that in the terminal if you have NPM.

$ cd ~/.vscode/extensions/gimly81.matlab
$ npm install vscode-textmate-languageservice@^latest

Hugefiles are still anemically slow but they don't block the UI thread completely.

ghost avatar Apr 05 '22 10:04 ghost

The fix in https://github.com/Gimly/vscode-matlab/issues/157#issuecomment-1088529259 doesn't work anymore.

Use the 2023 fix described in https://github.com/Gimly/vscode-matlab/pull/174#issuecomment-1435925969.


  It took +7700 lines of code... and another -6205 thrown out... but I killed all perf issues and made a 1.0.0-rc-1 release.
Next up is browser support 💪.

zm-cttae-archive avatar Jan 26 '23 23:01 zm-cttae-archive

@M00TSDNS — which repository are you referring to, you are not a contributor here AFAICT?

iandol avatar Jan 27 '23 04:01 iandol

which repository are you referring to

The Textmate LSP shim library, now on Gitlab.

Flip my username.. I wrote the library and cut new ground in VS extension ecosystem to do so :P (Github seems vulnerable to tag spoofing like Twitter and I don't want to self-spoof.)

As with others in #171, life happened and I didn't get to be able to fix the library issues. My new role is as a SDET with CI/CD and automation expertise so my work is paying me to fix the lib ... its a good way to figure out everything there is to know on Windows CI pipelines on Gitlab.

zm-cttae-archive avatar Jan 27 '23 13:01 zm-cttae-archive

This is releasing soonish!

zm-cttae-archive avatar Feb 26 '23 10:02 zm-cttae-archive