Daniel Mošmondor
Daniel Mošmondor

Reputation: 19986

Serialization with BinaryFormatter *PERFORMANCE* issues

Background:

I'm stuck with LARGE object graph that gets serialized into some 60MBs of file (and will grow over time). Problem isn't file size but writing and reading times, that go up to 4 minutes on some machines.

Plot:

Since this represents some kind of in-memory database, I can delay-load some of it.

Thrill:

How to measure loading time of specific object chunks? Do I log constructor invocations and go from there? Any better idea?

EDIT:

I would rather not talk about alternatives to serializing, there are lots of posts on that subject, I would rather investigate why is it so slow and what part of the object graph is the good candidate for 'excision' and delay load.

Upvotes: 1

Views: 1643

Answers (2)

Dmitrii Lobanov
Dmitrii Lobanov

Reputation: 4977

I would consider using SQL Server Compact (in-proc database from Microsoft) rather then serializing large graph of objects.

I had experience serializing large graph to disk using BinaryFormatter. There were issues related to versioning. Serialized objects are hard to maintain and work with also. And working with such objects generally require to de-serialise into memory. It is resource consuming way to work with large graph.

And Sql Server CE is quite lightweight, its assembly is about 1Mb. It also handles some multi-threading issues.

If you need to serialize just to send over network or whatever, I suppose 60Mb is quite large array, there can be problems transferring it.

Update

If you would like to go with BinaryFormatter, I suppose that you can serialize your graph not as one root object but as collection of smaller objects. Perhaps it would be slower to serialize all the objects but it will let you serialize only some part of objects. If you have heterogeneous array (i.e. sequence of objects of different types) I can suppose that the more complex object is and the deeper its hierarchy the more time it takes to serialize it. You can measure serialization time for a collection of objects of the same type. You also can use some profiler to serialize the whole graph, most profilers show you which method takes more time to execute.

Upvotes: 0

Aliostad
Aliostad

Reputation: 81700

You may try protobuf.NET which has been reported to be faster.

Upvotes: 1

Related Questions