News

Mono Linker Tool Now Reduces Size of .NET Core Apps

Microsoft is building on top of the Mono platform's handy Linker tool to turn its code-shrinking powers loose on reducing the size of .NET Core apps.

Mono -- an open source implementation of Microsoft's .NET Framework -- has an IL Linker for slimming down code projects.

"The linker is a tool one can use to only ship the minimal possible IL code and metadata that a set of programs might require to run as opposed to the full libraries," the project's GitHub site says. "It is used by the various Xamarin products to extract only the bits of code that are needed to run an application on Android, iOS and other platforms."

That has been modified and now also exists on GitHub as the .NET IL Linker.

"The .NET team has built a linker to reduce the size of .NET Core applications," the project states. "It is built on top of the excellent and battle-tested mono linker. The Xamarin tools also use this linker.

"In trivial cases, the linker can reduce the size of applications by 50 percent. The size wins may be more favorable or more moderate for larger applications. The linker removes code in your application and dependent libraries that are not reached by any code paths. It is effectively an application-specific dead code analysis."

Microsoft's Scott Hanselman put the tool through its paces in updating a 15-year-old .NET 1.1 application and realized different amounts of code shrinkage.

"You can see in some places where there's no size decrease," Hanselman said. "That's because I'm using those assemblies completely. Some see a 100 percent decrease -- they've been removed entirely -- because I'm not using the Registry, for example. And some see a fractional decrease because I'm using some methods but not others."

Microsoft has listed the following caveats for using the experimental tool:

  • Currently only supports publishing self-contained applications. It will fail unless you specify a runtime ID.
  • It is currently an experimental feature. We intend to productize it in a subsequent .NET Core release.
  • Linking only happens during publish, and therefore the linked app needs to be tested after publish, not just after build.
  • The linker can and will break some apps that use reflection. See Using IL Linker Advanced Features for more information about managing reflection usage.

The new experimental tool was released to the community to open it up for experimentation and solicit feedback to improve it. Specifically, Microsoft said it's looking for feedback on topics such as:

  • Linker throughput.
  • Cases where the linker can be more aggressive.
  • Cases where the link is too aggressive and causes applications to fail at runtime.
  • The linker provided an excellent result for a large application

Feedback can be provided by opening issues at either mono/linker or dotnet/core or via e-mail to [email protected].

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Hands On: New VS Code Insiders Build Creates Web Page from Image in Seconds

    New Vision support with GitHub Copilot in the latest Visual Studio Code Insiders build takes a user-supplied mockup image and creates a web page from it in seconds, handling all the HTML and CSS.

  • Naive Bayes Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the naive Bayes regression technique, where the goal is to predict a single numeric value. Compared to other machine learning regression techniques, naive Bayes regression is usually less accurate, but is simple, easy to implement and customize, works on both large and small datasets, is highly interpretable, and doesn't require tuning any hyperparameters.

  • VS Code Copilot Previews New GPT-4o AI Code Completion Model

    The 4o upgrade includes additional training on more than 275,000 high-quality public repositories in over 30 popular programming languages, said Microsoft-owned GitHub, which created the original "AI pair programmer" years ago.

  • Microsoft's Rust Embrace Continues with Azure SDK Beta

    "Rust's strong type system and ownership model help prevent common programming errors such as null pointer dereferencing and buffer overflows, leading to more secure and stable code."

  • Xcode IDE from Microsoft Archrival Apple Gets Copilot AI

    Just after expanding the reach of its Copilot AI coding assistant to the open-source Eclipse IDE, Microsoft showcased how it's going even further, providing details about a preview version for the Xcode IDE from archrival Apple.

Subscribe on YouTube

Upcoming Training Events