Xamarin – will namespace declaration in xaml affect performance?

Issue

Anyone know whether if namespace declaration in the xaml has any affect on the performance? Example,

<TabbedPage xmlns"http://xamarin.com/schemas/2014/forms"
            xmlns:x"http://schemas.microsoft.com/winfx/2009/xaml"            
            xmlns:local"clr-namespace:MyStaticDefinition">

where xmlns:local"clr-namespace:MyStaticDefinition" contains all my static variables definition.

To my understanding, reduce resource dictionary size will improve performance; but I couldn’t find anything online about namespace declaration in xaml

So … does:

  1. Having many namespace declaration in a page affects the page loading time?
  2. The size of the assembly affects the page loading time? Example in my MyStaticDefinition class, having 1 static variable vs 100 static variables

Solution

I’ve been digging through the XAML parser code in Xamarin.Forms and I would say that the performance implications of specifying a lot of XML namespaces in a XAML file is negligible if any at all.

Sure, the namespaces are loaded into a structure like: IList<KeyValuePair<XmlName, INode>>. This would of course grow with the amounts of namespaces you have and afterwards getting a specific namespace from this list takes some time too.

The parsing time would also grow with every namespace you add. Also, yes, the bigger the XAML file the longer it takes to deserialize it and parse it.

However, having 2 or 15 XML namespaces, won’t make much difference, since this is just one pass it needs to do to load this information.

You can inspect the code in XamlParser yourself and try to gauge the performance hits.

Answered By – Cheesebaron

Leave a Comment