开发者

C# Deserialization O(n*n) behaviour?

I have a serializable class (call it A) implementing ISerializable.

If I serialize about 11K of these in an array (as an array), deserialization takes about 1.3GB of max VM size to read about 170MB of disk image into a 250MB of final VM size. This takes about 5 mins (elapsed time), 4:20mins(CPU time).

If I serialize each of the above 11K objects individually to the same file (along with a count indicator), deserialization takes about 250MB of max VM size to read a slightly smaller (160MB) of disk image into a 250MB of final VM size. This takes about 35 secs (elapsed time), 20 seconds (CPU time).

Any ideas why? Seems strange. Both the cases above use binary serialization.

P.S. If it is relevant, there is开发者_Go百科 a bunch of contained serializable objects in instances of A each of these serialized objects are instances of classes that implement ISerializable.


I would presume that the incremental serialization process takes less time than serialization of the entire.array, as this incremental process creates short-lived objects. I.e when each object serialization is complete those objects created in the serialization process are no longer referenced, whereas I would imagine serialization of the entire array leads to a number of objects being referenced for longer. The .net garbage collector is optimized for objects that have a short life time and many of these objects are mostly kept in the cpu cache until a.generation 0 collection.

I would recommend getting a memory profiler and working out what the problem is. I've used the ANTS memory profiler in the past, and can recommend it.


There is a bug in the dot net serialization code that causes N^2 behavior: http://social.msdn.microsoft.com/Forums/en-US/netfxremoting/thread/442e95eb-683e-45c3-b84e-25b0b4037d75/#442e95eb-683e-45c3-b84e-25b0b4037d75

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜