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 for Converge360.

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube