dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.74k stars 3.99k forks source link

IDE should cache source-generated docs so that they are available for subsequent sessions without recomputation. #57532

Open CyrusNajmabadi opened 2 years ago

CyrusNajmabadi commented 2 years ago

IDE currently presumes that if nothing has changed in a project that all source generated results are valid and do not need recomptutation. This is a vital optimization as we don't want to be forced into recomputing generated docs out of fear that the generator might return different results on a subsequent run.

We can extend this optimization further and have the IDE not only compute the generated docs, but also cache them to our persistence store so that they are available on subsequent runs without regeneration. This will help features that want to run early, without paying the excessive cost necessary to generate docs (as that requires building full compilations).

An example of this is NavTo. NavTo does want to search generated docs to find matches. However, forcing the generators to run means paying for full compilations to built. This is enormously expensive and causes results to be very slow on initial search when navto has to wait on this.

Ideally, when nothing** had changed, we could just reuse the cached docs immediately and return results from them.

** We can define 'nothing had changed' how we want. However, at first approximation, it would be just checking the checksums for a project (specifically, the text inside of it, options, metadata references, and the checksums of referenced projects). If all of those were the same, then the same compilation would be generated, which implies the same generated docs would be produced.

dotnet-issue-labeler[bot] commented 2 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

sharwell commented 2 years ago

... when nothing** had changed ...

Completion defines this as "source generators ran on a prior project state, but have not yet run on the current project state". Checksums are intentionally allowed to differ.

This could also allow the IDE to reopen source generated documents without error.