Bug 9492 - System.Xml.Serialization 20X slower that on .Net
Summary: System.Xml.Serialization 20X slower that on .Net
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 2.10.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-01-11 10:07 UTC by Michael James
Modified: 2015-03-17 06:37 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Michael James 2013-01-11 10:07:13 UTC
A user has posted a problem on the Xamarin problem which he has encountered when using MonoTouch. It appears the problem is prevalent on Mono in general. Below is a link to the thread.


I tried to recreate the users problem by creating 2 lists of 500 objects. The objects in each lists differ by one having a nullable property. 

Run on Mono, the time it takes to serialize an object is about 20X that of the same code running on the .Net runtime. 

Although extremely honky code, below is simple console app which shows the problem created in less time it takes me to each a donut. 


using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;

namespace NullSerial
    class MainClass
        public static void Main(string[] args)
            var i = 1;

            timer = new System.Timers.Timer();
            timer.Interval = 1;
            timer.Elapsed += delegate

            NoneNullabe_Object = new List<NoneNullable>();
            Nullable_Object = new List<Nullable>();

            while (i <= 500)
                NoneNullable nno = new NoneNullable();
                nno.PaidAt = new DateTime();

            i = 1;

            while (i <= 500)
                Nullable n = new Nullable();
                n.PaidAt = new DateTime();

            Console.WriteLine("Nullable object count = " + Nullable_Object.Count);
            Console.WriteLine("None nullable object count = " + NoneNullabe_Object.Count);

            i = 0; 


            StringWriter writer1 = new StringWriter();

            XmlSerializer serializer1 = new XmlSerializer(typeof(List<Nullable>));
            serializer1.Serialize(writer1, Nullable_Object);


            Console.WriteLine("It took " + i + "ms to serialize the nullable objects");

            i = 0;

            StringWriter writer2 = new StringWriter();
            XmlSerializer serializer2 = new XmlSerializer(typeof(List<NoneNullable>));
            serializer2.Serialize(writer2, NoneNullabe_Object);


            Console.WriteLine("It took " + i + "ms to serialize the non nullable objects");
            i = 0;


        private static System.Timers.Timer timer;
        private static List<Nullable> Nullable_Object;
        private static List<NoneNullable> NoneNullabe_Object;


    public class NoneNullable
        public NoneNullable()
        public System.DateTime PaidAt {get; set;}

    public class Nullable
        public Nullable()
        public DateTime? PaidAt { get; set; }
Comment 2 Atsushi Eno 2015-03-17 06:37:24 UTC
XmlSerializer MUST be slow. Because we cannot use code generation based XmlSerializer on mobiles. Note that even Microsoft cannot make it faster because Apple prohibits dynamic code (they don't have interpreter-based XmlSerializer so it is just impossible anyways).