d-language-server / dls

A Language Server implementation for D
http://dls.dub.pm
106 stars 15 forks source link

Slow Code Analysis on Startup #44

Open ghost opened 5 years ago

ghost commented 5 years ago

For large codebases this can take a while to run. Especially if there are a lot of errors/warnings it can take up a lot of memory in VS Code. Other IDEs tend to only show this diagnostic data for open files or the currently open file. Possibly adding it as separate functionality to do code analysis on all files? Can't do anything else while this is running either, really annoying on startups.

https://github.com/d-language-server/dls/blob/master/source/dls/tools/analysis_tool.d#L178

LaurentTreguier commented 5 years ago

This is what DLS did originally, providing diagnostics only for currently open files. I had changed that as per Microsoft's recommendations for implementing language servers:

Basic Report diagnostics for open editors. Minimally, this needs to happen on every save. Better, diagnostics should be computed based on the un-saved contents of the editor.

Advanced Report diagnostics not only for the open editors but for all resources in the open folder, no matter whether they have ever been opened in an editor or not.

But I agree, I tested it on the DMD codebase once and DLS struggled to gather all 2k or so diagnostics. On Windows, even on its own codebase the startup time is sometimes annoying actually... I'll add an option to toggle this behavior on or off.

ghost commented 5 years ago

It might be fine if it runs in the background, but it blocks pretty much everything else for DLS. Also looking at the output window is kind of laggy because there ends up being 100,000+ warnings.

LaurentTreguier commented 5 years ago

Are you using multiple workspaces or sub-projects ? There seemed to be a bug where DLS would potentially re-analyze everything multiple times over. I reduced that with the upcoming v0.25.5, though it will probably still be very slow after that nonetheless

ghost commented 5 years ago

Yah I had the DMD layout src/phobos src/druntime src/dmd in one folder. Not sure if it checked everything twice, may have been doing that. But yah a setting to toggle it off/on would work as well. I don't usually need it. A separate function could work too, though that would be editor specific. Not part of the language server. Ctrl+Shift+P in VS Code then the command like "DLang Analysis entire workspace" or something. Would be more work to do that I feel.

ghost commented 5 years ago

https://github.com/d-language-server/dls/blob/master/source/dls/tools/analysis_tool.d#L195

        foreach (file; discardedFiles)
        {
            send(TextDocument.publishDiagnostics, new PublishDiagnosticsParams(file, []));
        }

This is taking ~50 seconds for me. From the looks of it, it isn't even doing any analysis, it is just pushing messages. Could be that sending messages is just really slow? There's about 7000 but it still shouldn't be taking a minute to send that many messages. I tried using both stdio/sockets took about the same amount of time.