Enable Trimming to Reduce MAUI App Size
- 2 minutes to read
Deployment size optimization matters for mobile apps, because hand-held devices are usually limited in memory resources. The .NET Linker tool can help optimize your app’s deployment size. In the Release build configuration, the Linker runs trim operations - it removes unused libraries and unnecessary code parts. The libraries must be compatible with such operations.
If you use DevExpress controls in a MAUI application, you can enable trim operations for the DevExpress.Data library. To do this, include the following line to the project file (.csproj). Note that our Project Templates add this line automatically.
<ItemGroup>
<!--...-->
<PackageReference Include="DevExpress.Maui.DataGrid" Version="22.2.*" />
<TrimmableAssembly Include="DevExpress.Data.v22.2" />
</ItemGroup>
Important
The DevExpress.Data library is adapted to be trimmed when using with DevExpress MAUI components. If you use DevExpress.Data API directly or use other libraries that reference it, do not enable trimming to avoid unexpected runtime exceptions.
Deployment Size Tests
This section illustrates how trim operations affect the resulting app size. We tested the following app configurations:
Empty MAUI app – A .NET 7 project that is created based on the default MAUI template in Visual Studio.
DevExpress app – A .NET 7 project that references all the DevExpress.Maui libraries including DevExpress.Maui.Charts, DevExpress.Maui.Scheduler, and so on.
DevExpress app with trimming enabled – A project that duplicates the previous configuration with DevExpress.Data marked as a trimmable assembly.
The following tables show the difference in the resulting app sizes:
iOS
App Type | App Size |
---|---|
Empty MAUI app | 41.04 MB[1] |
DevExpress app | 121.33 MB[1] |
DevExpress app with trimming enabled | 86.06 MB[1] |
Android
App Type | App Size |
---|---|
Empty MAUI app | 15.19 MB[1] |
DevExpress app | 26.81 MB[1] |
DevExpress app with trimming enabled | 22.4 MB[1] |
For more information about the app size and tools that inspect referenced packages, refer to the following page: App Size Reporting Tools.