Xamarin.Mac Performance

PDF for offline use
Related Links:

Let us know how you feel about this

Translation Quality


0/250

last updated: 2017-11

Xamarin.Mac applications are similar to Xamarin.iOS, and many of the same performance suggestions are applicable:

but there are a number of macOS specific suggestions that may be helpful.

Prefer Modern Target Framework

There are multiple Target Frameworks available to Xamarin.Mac application with different performance characteristics and features.

When possible, prefer Modern and work with dependent libraries to add support. Only the Modern Target Framework allows linking which can drastically reduce assembly sizes. This becomes especially important when enabling AOT, as AOT compilation of Full assemblies can produce large final bundles.

Enable the Linker

Startup time, both in load and "Just In Time" (JIT), scales somewhat linearly with the size of your final binaries. The easiest way to improve this is by removing dead code with the linker.

While this suggestion primarily applies to Modern Target Framework users, use of Platform Linking can provide a limited performance boost as well.

Enable AOT When Appropriate

Another facet of startup performance is the JIT compilation of assemblies into machine code. Ahead of Time (AOT) compilation can significantly reduce startup time, but comes with a number of tradeoffs covered in the AOT documentation.

Ensure Performant Delegates

Many Xamarin.Mac applications are centered around Cocoa views such as NSCollectionView, NSOutlineView, or NSTableView. Often these views are powered by Delegate and DataSource classes you provide to Cocoa, answering questions on what to display.

Many of these entry points are invoked often, sometimes multiple times per second when scrolling.

Make sure these functions return values that are easily calculated or use information already cached, to prevent the user interface from blocking.

Use Cocoa Provided APIs for Reusing Views

Many Cocoa views that contain many child views or cells (such as NSCollectionView, NSOutlineView, and NSTableView) provide APIs for creating and reusing views. These create pools of shared items and prevent performance issues when scrolling through the views quickly.

One example of this is in the NSOutlineViewAndTableView Sample.

Use Async and Do Not Block the UI

Desktop applications often process large quantities of data and it is very easy to block the UI thread waiting on a synchronous operation.

Whenever possible, use async and threads to prevent blocking the UI.

For long running operations consider using NSProgressIndicator or other options noted in Apple’s HIG to notify users.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.