-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable targeted Assembly trimming #49040
Comments
Tagging subscribers to this area: @vitek-karas, @agocke, @CoffeeFlux Issue DetailsNarrowing the impact of the Linker to a single Assembly to trim would be convenient for scenarios involving large monolithic SDK style assemblies. The scenario would permit consuming one of the assemblies from https://github.com/dotnet/pinvoke and indicating that only the P/Invoke assembly should be trimmed. The Linker would run over the entire application but the trimming operation would be limited to the P/Invoke assembly. This shouldn't be constrained to a single assembly but rather to a collection that can be impact and all other assemblies just used to determine usage.
|
There's an option that tells the linker to trim a particular assembly:
Whatever MSBuild logic adds that assembly to the output could set some metadata on it to pass the above option to the linker. The current linker defaults will analyze starting from the entry point and any referenced assemblies without IsTrimmable assembly metadata - usually the app and nuget dependencies, since we add this attribute to framework assemblies. If your scenario is compatible with the usual caveats of
If you were specifically looking to avoid trimming any other assemblies (to avoid problems with unanalyzable reflection for example), we could pass
However this is a lot of analysis to do (scanning the entire self-contained app's IL) if we are only going to optimize that one assembly. In that case it might make more sense to develop a solution particularly for your scenario (maybe there are more efficient ways to only look for references to the generated PInvokes). There's another important caveat, which is that even with |
Trimming doesn't happen unless the user specifies |
Trimming can cause runtime malfunction do to removal of private members that are accessed via reflection. Yet some assemblies are relatively safe from such regressions and would greatly benefit from trimming, such as the Win32 p/invoke assemblies mentioned above. So yes, I think the ask is to trim specific assemblies all the time. That said, given trimming requires scanning all assemblies deployed with an app so only APIs unused across the whole app can be removed from the assembly, perhaps that would take an unacceptable toll on build perf, I don't know. Can we limit trimming when the user does ask for it to just those assemblies that the app knows are "safe" to trim? |
We do limit trimming to assemblies marked
I think for this we would want to add support for |
I think you are asking for exactly what Sven shared earlier. You can mark your assembly as https://github.com/mono/linker/blob/main/docs/design/trimmed-assemblies.md#assemblymetadataistrimmable-true trimmable and that will trim it all the time automatically. |
Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer Issue DetailsNarrowing the impact of the Linker to a single Assembly to trim would be convenient for scenarios involving large monolithic SDK style assemblies. The scenario would permit consuming one of the assemblies from https://github.com/dotnet/pinvoke and indicating that only the P/Invoke assembly should be trimmed. The Linker would run over the entire application but the trimming operation would be limited to the P/Invoke assembly. This shouldn't be constrained to a single assembly but rather to a collection that can be impact and all other assemblies just used to determine usage.
|
Narrowing the impact of the Linker to a single Assembly to trim would be convenient for scenarios involving large monolithic SDK style assemblies. The scenario would permit consuming one of the assemblies from https://github.com/dotnet/pinvoke and indicating that only the P/Invoke assembly should be trimmed. The Linker would run over the entire application but the trimming operation would be limited to the P/Invoke assembly.
This shouldn't be constrained to a single assembly but rather to a collection that can be impact and all other assemblies just used to determine usage.
The text was updated successfully, but these errors were encountered: