0

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
4
  • Is your question, whether declaring a lesser number of namespaces gonna increase performance?
    – FreakyAli
    Aug 17, 2021 at 5:35
  • I've edited my original post
    – SimonSays
    Aug 17, 2021 at 8:04
  • If you are using compiled XAML, I would say that it wouldn't have any performance implications, especially if you are also linking your code. Adding a couple of namespace declarations wouldn't tank performance. Aug 17, 2021 at 9:59
  • @Cheesebaron, thanks for the confirmation and highlight the use of compiled XAML. If you would copy your comment into a post, I will be glad to mark it as the answer
    – SimonSays
    Aug 18, 2021 at 3:41

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.