This project has moved and is read-only. For the latest updates, please go here.

Slow BSON deserialization/deserialization

May 4, 2010 at 6:21 PM

It look like BSON serialization/deserialization for complex objects are much slower than DataContractSerializer. In my test I tried "AdvetureWorks/EF 4.0/Self Tracking Entities" (products = context.Products.Include("ProductProductPhotoes").ToArray();) and here are the results:

                                 DataContractSerializer                 BSON

Serialization:              37 msec                                     80 msec

Deserialization:          70 mscec                                    300 msec

Am I missing something?

            using (var ms = new MemoryStream())
                var serializer = new JsonSerializer();
                var writer = new BsonWriter(ms);
                serializer.Serialize(writer, products);               
                productsByte = ms.ToArray();
                Console.WriteLine(String.Format("Elapsed time for BSON: {0}", watch.Elapsed));
                var serializer = new JsonSerializer();
                Product[] products1;
                using (var ms = new MemoryStream(productsByte))
                    var reader = new BsonReader(ms, true, DateTimeKind.Unspecified);
                    products1 = serializer.Deserialize<Product[]>(reader);

May 5, 2010 at 2:58 AM

I don't know why. I'd really need to check it out in a profiler to see what is taking time.