DavidFeldhoff / al-codeactions

MIT License
17 stars 8 forks source link

Poor Performance with AL Lang v13 #177

Closed mjmatthiesen closed 5 months ago

mjmatthiesen commented 5 months ago

Since updating to v13.0.964488, saving files in larger codebases has started taking a long time. For this previously CAL now AL project, while saving, it can take minutes. Within this project, small files save faster, but still much slower than the average few files few hundred lines PTE.

I assume v13 is probably breaking stuff, and that's likely where this new performance issue is coming from, but also, CodeActions is executing on save and definitely should not be since it offers no save actions.

image

If something goes wrong, I will get a whole swath of changes, new lines for procedure params, extra indents, empty new lines, removal of some of the variable type, removal of then/begin, and so on.

image

An example of new lines and indents

image

variable type, also happen for records

image

Now, once I disable CodeActions it looks to work as expected, file saving happens in a second.

What I am surprised by, is that there aren't even save actions available within the settings, so I'm not sure what causes the extension to trigger. Been a long time since I've created one, but I would have assumed you could exclude yourself from save actions.

Now I do have the two following settings, as I do want to format on save:

    "editor.formatOnSave": true,
    "alOutline.codeActionsOnSave": [
        "SortProperties"
    ],
    "editor.codeActionsOnSave": {
        "source.fixAll.al": "explicit"
    },

But I still wouldn't expect code actions to run, nor pop up in that save list at all.

If there's a log I can produce for this, let me know and I'll do it. I use the extract to label a lot.

DavidFeldhoff commented 5 months ago

Hey @mjmatthiesen. Thanks for the detailed explanation. I searched a bit and found the "code action context". Mostly it is undefined, but e.g. with this setting

"editor.codeActionsOnSave": {
        "source.fixAll.al": "explicit"
    }

the providers are executed with an "explicit"-context on save and now I'm stepping out there directly. So my providers are now only executed if the context is QuickFix (or in some cases also refactor). That should fix already the thing that the AL CodeAction providers are popping up during the OnSave. Furthermore I introduced a new setting alCodeActions.executeCodeActionsAutomatically which defaults to true (as that is the VS Code's default). Automatic requests are done by VS Code nearly on each cursor change, so the providers are executed nearly all the time. By using the editor.lightbulb.enabled you could turn the lightbulb off and with that also the most of the automatic calculcations. But in case you don't want to turn off all code action providers, but only the ones of AL CodeActions, then with the newly introduced setting there's also a way that my providers only kick in if you explicitly click Ctrl + . or the appropriate command Quick Fix.... Give it a try and let me know if it helps. Best regards, David

mjmatthiesen commented 5 months ago

Danke für das Update!

I have it set to explicit (the default, used to be true), so that they don't trigger on file auto saves.

I like the light bulb, serves as a nice reminder that something can potentially be improved. I've just updated and will run with the new version today. If I experience any further issues, I can turn off the light bulb with the new config. Thanks!

DavidFeldhoff commented 5 months ago

Great, if you experience further performance issues I'd be happy if you let me know :)