Skip to content
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

[wasm] trim System.Private.Uri.dll #74826

Merged
merged 4 commits into from
Aug 31, 2022

Conversation

pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Aug 30, 2022

In the legacy interop, we have edge case use-case: when somebody would bind_static_method("Foo") where void Foo(Uri uri) the old marshaler would marshal string as Uri instance in Net6.
This feature costs about 103KB of System.Private.Uri.dll uncompressed for all runtime/wasm users, regardles if they use it or not.

This changes the code so that ILLink would not protect Uri class and it could be trimmed out.

I think that if the user code calls methods with Uri parameter, they probably also have the Uri constructor in scope.

Even if they don't have it, they could configure ILLink to protect Uri after they enabled trimming.

My.csproj

  <ItemGroup>
    <TrimmerRootDescriptor Include="$(MSBuildThisFileDirectory)ILLink.Descriptors.xml" />
  </ItemGroup>

ILLink.Descriptors.xml

<linker>
  <assembly fullname="System.Private.Uri">
    <type fullname="System.Uri">
        <method signature="System.Void .ctor(System.String)" />
    </type>
  </assembly>
</linker>

@pavelsavara pavelsavara added this to the 8.0.0 milestone Aug 30, 2022
@pavelsavara pavelsavara requested review from kg and radekdoulik August 30, 2022 17:06
@pavelsavara pavelsavara self-assigned this Aug 30, 2022
@ghost
Copy link

ghost commented Aug 30, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

In the legacy interop, we have edge case use-case: when somebody would bind_static_method("Foo") where void Foo(Uri uri) the old marshaler would marshal string as Uri instance in Net6.
This feature costs about 80KB of System.Private.Uri.dll uncompressed for all runtime/wasm users, regardles if they use it or not.

This changes the code so that ILLink would not protect Uri class and it could be trimmed out.

I think that if the user code calls methods with Uri parameter, they probably also have the Uri constructor in scope.
Even if they don't have it, they could configure ILLing to protect Uri it after they enabled trimming.

Author: pavelsavara
Assignees: pavelsavara
Labels:

arch-wasm, area-System.Runtime.InteropServices.JavaScript

Milestone: 8.0.0

@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

@pavelsavara pavelsavara requested a review from maraf August 30, 2022 17:07
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@radekdoulik radekdoulik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that it is a corner case, I think it is fine. For NET8 it will make sense to add a new feature switch for the legacy JS interop as discussed on discord and hide the reflection behind it.

@radical
Copy link
Member

radical commented Aug 31, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara pavelsavara marked this pull request as ready for review August 31, 2022 06:40
@pavelsavara pavelsavara requested a review from lewing as a code owner August 31, 2022 06:40
@pavelsavara
Copy link
Member Author

Uncaught Error: System.MissingMethodException: Constructor on type 'System.Uri' not found. Please consider to protect it's constructor from trimming.
 ---> System.MissingMethodException: Constructor on type 'System.Uri' not found.
   at System.RuntimeType.CreateInstanceImpl(BindingFlags , Binder , Object[] , CultureInfo )
   at System.Activator.CreateInstance(Type , BindingFlags , Binder , Object[] , CultureInfo , Object[] )
   at System.Activator.CreateInstance(Type , Object[] )
   at System.Runtime.InteropServices.JavaScript.LegacyExports.CreateUriRef(String uri, Object& result)
   --- End of inner exception stack trace ---
   at System.Runtime.InteropServices.JavaScript.LegacyExports.CreateUriRef(String uri, Object& result)

This is how it looks like when the constructor was trimmed.
I also tested that the ILink configuration makes it work again, see top post.

@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara pavelsavara merged commit d48dd6c into dotnet:main Aug 31, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 30, 2022
@pavelsavara pavelsavara deleted the wasm_trim_uri_dll branch October 13, 2022 10:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants