Xamarin - will namespace declaration in xaml affect performance? - xamarin

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:
Having many namespace declaration in a page affects the page loading time?
The size of the assembly affects the page loading time? Example in my MyStaticDefinition class, having 1 static variable vs 100 static variables

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.

Related

Is it better to use a JSON configuration file that loads at the beginning of App or using classes that has static/final variables in Flutter?

I'm creating an app using Flutter that has around 1500+ predefined colors and gradients.
I was wondering should I create a configuration file that always loads at the beginning of the app or should I create a class that has static final/const variables such as map+list?
Which one would be more memory efficient, less error prone and code friendly?
Any suggestions?
Thanks a lot!
Thanks for all the comments. Now since I don’t need to do update OTA, I decided to create a class with static map+list combination
I found the benefits are:
1. Less error prone because the naming will be checked by editor.
2. Only loaded in pages where we need it.
3. Compared to reading from a JSON files, it doesn’t need async functions to get the data thus faster. Because File reading is an I/O operation

How to re-render certain object descriptions with Sphinx docs?

Using Sphinx's domain-aware ObjectDescriptions I can create fancy rendered documentation for them. For example:
.. py:function:: pyfunc()
Describes a Python function.
This renders the content in a nice way, and this works really well with module indices, references and so on. Cool so far!
Now, let's say I have that directive in a source document src/mymodule/functions.rst, and I have a bunch of text in src/guide/getting-started.rst, I can reference to the objects like
:py:func:`pyfunc`
Also cool!
Now, my actual question; Could I also tell the Sphinx writer to re-render the same documentation snippet for that object? To ease the user in not having to navigating away from the Getting Started page where I just want to include a single piece of content again.
What I've tried to do:
Simply copy the contents. This results in a warning that the object is defined multiple times, hurts the index and as a result references don't point to the "authoritative" place in your project, if unlucky. Not okay.
Document each object in its own file and then use .. include:: rel/path/to/pyfunc.rst in each document where I want to render it. As those includes are literal on ReST-level, this results in the same downsides as the option above. :-(
Thus, I'm looking for a solution where I would tell the renderer/writer of Sphinx to simply re-render the contents of a reference instead of producing a link. It should not add it to the index for a simple re-render.
I'm okay with a custom extension or a domain-specific custom solution - I'm already using my own custom domain, but I just used the general Python domain above as a well-known example.
Context for the use case: I'm building a Protobuf domain. Protobuf messages and enums are reused a lot and I would like to show the context of commonly reused objects inline on pages where this is useful to the reader. This means it is repeated over the whole project on purpose where it is deemed useful rather than navigating away all the time. Yet only the reference page should be "authoritative".
I've been successful with a dirty hack: abusing the XRef role logic. Cross-references in Sphinx render dynamically (e.g. Table 23) by producing arbitrary 'nodes'. By:
keeping a copy of the parent node during parsing in a custom Domain
registering a custom Sphinx/ReST XRef role to render a whole set of nodes (the saved parent node)
re-running the ReferencesResolver another time
... this basically does what I need. But yuck, it's rather ugly.
Working example I implemented in a Protobuf Domain extension.

Is There Any Overhead Difference Between Protobuf Runtime and Static Tag Methods?

We are using Probuf on a .netcf target. Everything works well. I started out using the static [ProtoContract], [ProtoMember, 1].. etc. My colleage was concerned about adding potential overhead to the class object so I switched to a runtime model with .add(# , " ") which seemed more "disconnected" from the class in question. I actually prefer the static tags in the class since names are inherently updated if variable names are refactored later. Since I do not know how or what protobuf does under the hood, is there any advantage or disadvantage to using the static tags vs. the runtime model in terms of overhead, speed, etc.
Thanks!
I haven't profiled this aspect extensively - mainly because any overhead from reflection on the attributes is done once and once only. There might be a slight difference in cold-start performance, but: if the ultimate in startup performance is your aim you should ideally try to use the precompiler available in the google-code download. This only works with the attribute model but has the advantage that when using a precompiled model no reflection whatsoever occurs at runtime. It will also generate pure IL, where-as CF is usually very restricted so IIRC the runtime usage is forced to use some reflection even for things like member access. Finally, it means you can use the "CoreOnly" rather than "Full" build, which is smaller and less complex.
http://marcgravell.blogspot.co.uk/2012/07/introducing-protobuf-net-precompiler.html

Magnolia Blossom : Two pages sharing the same area

I'm using the Magnolia Spring Integration (Blossom) for my web app and I definitely don't understand how (if it's even possible) to share a unique area between two pages.
This is how I've worked so far :
I have three templates main-template, template-1 and template-2.
template-1 and template-2 both redirect to main-template by redefining their own "body" areas.
In the class of template-1 I have three areas : content-area, area-1 and area-2
In the script of template-1 I include the three areas with the following directives : [#cms.area name="content-area"/], [#cms.area name="area-1"/] and [#cms.area name="area-2"/]
The same areas are defined in the template-2 class and script
What I want is to share, lets say, area-1 between template-1 and template-2. The problem is that by redefining them in each class they are considered like different areas...
Through my tests and the magnolia documentation, what I understand is that an area can only be defined within a template class so it can be accessed in the script of this template and only the areas defined directly in the template class associated with the page will be process/rendered.
No matter what I try, as long as the areas are not defined in the page's template class they cannot be accessed and therefore included pages don't have their areas rendered.
Does anyone have a clue in how I can "include" or process "areas" from other templates in another one ? Or am I doing it all wrong ?
Thank you for your time.
regards.
I know this is an old question, but it is still a valid question, so let me answer it:
As far as I know areas can inherit from other areas (normal Java class inheritance using "extends ..."). As far as I know this wasn't available in 2013 yet, but it is now. I know this because I filed this as a feature request once and it was marked as solved at some point, and I think I also successfully used it once (don't remember clearly).
If for some reason it's still not possible to extend areas from super classes, then you could still use conventional tools like putting the logic to a helper class and making the actual areas very slim (that is just calls into the shared helper class). And the actual template (.jsp or .ftl file) can be shared anyway.

Object does not match target type in DesignData

I'm throwing this out in case someone has encountered this before.
When creating DesignData for use within the WPF designer, I get one of two errors:
Object does not match target type.
at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object
target)
(SNIP)
at Microsoft.Expression.DesignModel.InstanceBuilders.ClrObjectInstanceBuilder. UpdateProperty(IInstanceBuilderContext
context, ViewNode viewNode, IProperty
propertyKey, DocumentNode valueNode)
The other one is a little more informative:
The value "_.di0.MyProjectLol.MyType"
is not of type "MyProjectLol.MyType"
and cannot be used in this generic
collection.
at
System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object
value, Type targetType)
(SNIP)
at Microsoft.Expression.DesignModel.InstanceBuilders.ClrObjectInstanceBuilder.
InstantiateChildren(IInstanceBuilderContext
context, ViewNode viewNode,
DocumentCompositeNode compositeNode,
Boolean isNewInstance)
When debugging, I can see that there is a dynamic assembly that is loaded with proxy-ish types that look like mine but, obviously, are not. This assembly is called Blend_RuntimeGeneratedTypeAssembly(Guid goes here). When attempting to load types in this assembly, it throws a type load exception for a number of them. So, some types get proxied, some types are left as God and I intended, and when they mix unnatural acts occur.
For example, the type "Foo" might get a proxy created, but no other types do (TypeLoadExceptions). Then the designer tries to hand one of my real types the proxy (helped by the fact that xaml serialization likes to cast collections to IList, thus shitting on type safety) and you get one of the above exceptions.
I have spent half a week trying to fix this. I've tried a hundred different things, but I can't figure out exactly what is causing it to fail. Suggestions are welcome, TIA.
Solution in two parts:
1) Ensure VS is fully updated. At this point, it means installing the Silverlight 4 tools for Visual Studio 2010. They include the latest updates to the WPF designer. If you're reading this off in the distant future, ignore this one.
2) Hit the properties for your design data files. Clear out "Custom Tool", and set the "Build Action" to either "DesignData" or "DesignTimeDataWithDesignTimeCreatableTypes".
DesignData means that your types cannot be deserialized from xaml directly (due to dependencies or the such), so the designer attempts to create mocks for those types and presents the mocks to your design surface.
DesignTimeDataWithDesignTimeCreatableTypes means that the designer will load your assemblies and deserialize the xaml directly into your types without creating mocks.
This can also be caused by a certain combination of situations that, when combined, cause deserialization to fail.
Essentially if you have
A custom collection, or a collection that doesn't implement IList
That is exposed as a property on your type
Which is defined in a different assembly
you can get this error message as well.
It is very important that your collection property types implement IList (the non-generic one) if you want to serialize them to and from xaml!

Resources