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.88k stars 4.01k forks source link

Microsoft.CodeAnalysis.* trimming support #68154

Open KirillKornienko opened 1 year ago

KirillKornienko commented 1 year ago

In my application, I parse some user code using SyntaxFactory.ParseExpression() API. Since this application is used in WASM, the size of the application is critical, but unfortunately Microsoft.CodeAnalysis.dll, Microsoft.CodeAnalysis.CSharp.dll and Microsoft.CodeAnalysis.VisualBasic.dll libraries do not support trimming and only these libraries occupy a total of 13.3 MB of size, which is quite a lot.

Version Used: 4.5.0

Steps to Reproduce:

  1. Create an empty dotnet wasm project (.NET 7)
  2. Add package references to Microsoft.CodeAnalysis.CSharp and Microsoft.CodeAnalysis.VisualBasic latest versions.
  3. Publish application.

Expected Behavior:

The unused API in these libraries will be cut and the resulting application size will be reduced.

Actual Behavior:

Microsoft.CodeAnalysis.* libraries don't support trimming and they take up a lot of disk space.

dotnet-issue-labeler[bot] commented 1 year 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.

jcouv commented 1 year ago

This is already being addressed in PR https://github.com/dotnet/roslyn/pull/66519 (which is still being reviewed)

JakeYallop commented 3 months ago

Any updates on this? This is something I'd love to have. At the moment without trimming annotations, there's a lot of trial and error to figure out what to tell ILLink to try to get some form of size reduction.

As written, this issue also covers things like Microsoft.CodeAnalysis.Features or Microsoft.CodeAnalysis.Workspaces, which are themselves large undertakings. Is it worth splitting those (and possibly other parts of Microsoft.CodeAnalysis) out into separate issues, and to scope this one to a smaller chunk of work that might be more achievable?