Skip to content

Annotate DependencyInjection to make it linker friendly #39745

Closed

Description

@eerhardt

The DependencyInjection library uses IL Emit and Reflection in order to create service implementations. However, this isn't linker friendly because the ILLinker will trim the constructors from these types, since it doesn't know anyone is using them.

We should annotate the DependencyInjection library with DynamicallyAccessedMembers attributes, so the ILLinker knows to preserve the constructors correctly. This should allow us to remove the Microsoft.Extensions.* assemblies from Blazor's "type granularity" list, and instead fully trim these assemblies, just like the System.* assemblies.

I have a prototype of this here, where the size reduction is decent:

Uncompressed IL file sizes:
- Before 2,425,856 bytes
- After 2,360,320 bytes

Compressed (.br) all file sizes in wwwroot_framework:
- Before 1,464,786 bytes
- After 1,443,696 bytes

We can see a ~20 KB size reduction in the Brotli compressed file sizes with this change.

cc @pranavkm @SteveSandersonMS @joperezr @layomia @davidfowl

Activity

  1. added
    linkable-framework
    on Jul 21, 2020
  2. added
    untriaged
    on Jul 21, 2020
  3. added this to the 5.0.0 milestone on Jul 22, 2020
  4. removed
    untriaged
    on Jul 22, 2020
  5. modified the milestones: 5.0.0, 6.0.0 on Jul 27, 2020
  6. eerhardt commented on Jul 27, 2020

    @eerhardt
    MemberAuthor

    Moving to 6.0, as the size savings here is not critical for 5.0.

  7. davidfowl commented on Jul 31, 2020

    @davidfowl
    Member

    Any chance we can do this in 5.0? Is there any harm?

  8. added a commit that references this issue on Aug 1, 2020
    60e7359
  9. added a commit that references this issue on Aug 2, 2020
    a5159b1
  10. added a commit that references this issue on Aug 10, 2020
    ccdd619
  11. ghost locked as resolved and limited conversation to collaborators on Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Extensions-DependencyInjectionlinkable-framework

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions