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

Strip the ILLinkTrim.xml file from System.Private.Xml #35547

Merged
merged 2 commits into from
May 1, 2020

Conversation

eerhardt
Copy link
Member

@eerhardt eerhardt commented Apr 28, 2020

The two methods being preserved in System.Private.Xml (CreateSqlReader and GenerateSerializer) are large, and are not necessary when linking a mobile app. These methods only need to be preserved when linking the shared framework. When a normal app is linked, the linker is able to figure out if the two methods are necessary.

Contributes to #35199

Fixes #30912

@ghost
Copy link

ghost commented Apr 28, 2020

Tagging subscribers to this area: @buyaa-n, @krwq
Notify danmosemsft if you want to be subscribed.

@stephentoub
Copy link
Member

stephentoub commented Apr 28, 2020

When a normal app is linked, the linker is able to figure out if the two methods are necessary.

Is #30912 addressed then as well? The linker recognizes the pattern used in

s_createSqlReaderMethodInfo = typeof(System.Xml.XmlReader).GetMethod("CreateSqlReader", BindingFlags.Static | BindingFlags.NonPublic);
? Should we add PreserveDependency anyway, to make it explicit?

@eerhardt
Copy link
Member Author

eerhardt commented Apr 28, 2020

Is #30912 addressed then as well? The linker recognizes the pattern used in

s_createSqlReaderMethodInfo = typeof(System.Xml.XmlReader).GetMethod("CreateSqlReader", BindingFlags.Static | BindingFlags.NonPublic);
?

Yes, I tested it on a standalone application:

        static void Main(string[] args)
        {
            SqlXml x = new SqlXml();
            XmlReader r = x.CreateReader();
            Console.WriteLine(r);
        }

And told the linker --ignore-descriptors true (which ignores the ILLinkTrim.xml file during the app build), and it still preserved the internal XmlReader.CreateSqlReader method. I then removed the x.CreateReader() call, and the internal XmlReader.CreateSqlReader method was removed.

Should we add PreserveDependency anyway, to make it explicit?

I think that is a good idea. I like being explicit so we don't have any surprises in case the linker changes behavior or has a bug.

A problem to be solved here is how we test this so we can catch regressions. We don't really have the capability of linking test applications today. Maybe once Xamarin apps are fully plumbed into our builds, we could make a Xamarin app that does similar to the above, and we run it to ensure it behaves correctly?

@eerhardt
Copy link
Member Author

eerhardt commented Apr 28, 2020

Just a note for the size difference this change makes on the WorldCities Xamarin app:

Here's the linked app without the change:

image

And here's the linked app with this change:

image

NOTE: the linker-dependencies.xml.gz file is not part of the app. It contains the dependencies between all the code, and it helps analyze why a method/type is kept in the trimmed app.

Copy link
Contributor

@marek-safar marek-safar left a comment

Choose a reason for hiding this comment

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

Perhaps instead of hard to notice flag in csproj we could call the XML file differently for this mode and use that to control the logic. We also need to be careful not to ever build this library twice.

@eerhardt
Copy link
Member Author

Perhaps instead of hard to notice flag in csproj we could call the XML file differently for this mode and use that to control the logic.

This is a good idea. I've implemented it. I went back and forth on some different names:

  • ILLinkTrim_NonEmbedded.xml
  • ILLinkTrim_Stripped.xml
  • ILLinkTrim_SharedFrameworkOnly.xml

but settled on ILLinkTrim_LibraryBuild.xml. Let me know what you think. I can definitely change the file name if a better name is chosen.

The two methods being preserved in System.Private.Xml (CreateSqlReader and GenerateSerializer) are large, and are not necessary when linking a mobile app. These methods only need to be preserved when linking the shared framework. When a normal app is linked, the linker is able to figure out if the two methods are necessary.

Contributes to dotnet#35199
- Add PreserveDependencyAttribute to SqlXml to be explicit.
- Rename ILLinkTrim.xml to ILLinkTrim_LibraryBuild.xml when it shouldn't be embedded in the resulting assembly.
@marek-safar
Copy link
Contributor

Let me know what you think. I can definitely change the file name if a better name is chosen.

This looks good! About the name, I'd personally go with ILLink.Descriptors.Build.xml but I'm fine with what you like.

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.

Address SqlXml to CreateSqlReader dependency for assembly size
5 participants