Fastest possible serialization

D

_DD

I had one experimented with binary serialization of an ArrayList of
structs (each struct mostly contains strings). Strangely enough, it
did not run as fast as custom XML storage (latter was nothing fancy,
but did not use normal serialization). I was not pressed to get
runtime optimized at the time, so I just went with XML.

The situation has shifted, and I have to figure out the *fastest
possible* way to save and reload that ArrayList. I remember seeing
something on optimizing serialization but could not locate it. Are
there recommended approaches? (again with speed as the major concern)
 
N

Nicholas Paldino [.NET/C# MVP]

_DD,

The fastest possible serialization will be from creating a custom
routine which will write binary representations of the field values to a
stream. You will have to code the routines for each type, as you will face
an overhead if you use reflection. This is what serialization "suffers"
from now.

Not that I have a problem with optimizations, but you have weigh the
benefits of these optimizations. You will have to add code to every type
every time you add a field.

What are your performance goals? Going for "as fast as possible" isn't
really a good performance goal. Rather, you should have a benchmark and try
and hit that. You might find other areas of the application where you can
make optimizations which would not be do broad (you are talking about a
custom solution which requires implementation of every type that
participates in it, which can be a maintinence nightmare, to say the least)
and help you hit your performance goals.

Hope this helps.
 
D

_DD

The fastest possible serialization will be from creating a custom
routine which will write binary representations of the field values to a
stream. You will have to code the routines for each type, as you will face
an overhead if you use reflection. This is what serialization "suffers"
from now.

The first method was pretty much by the book, but I may have missed
something. It took about twice as long as parsing the equivalent XML
file.

Do you have a feel for how much of a performance hit is imposed by
reflection? I thought that serialization could be fairly fast,
especially compared to verbose XML. That was a shock.
Not that I have a problem with optimizations, but you have weigh the
benefits of these optimizations. You will have to add code to every type
every time you add a field.
What are your performance goals? Going for "as fast as possible" isn't
really a good performance goal. Rather, you should have a benchmark and try
and hit that.

If there was a spec for this particular function, it would be: "Fast
as hell" <g> Seriously, it is one of those things that will end up
'inline' with user interaction, and the most entertaining progress bar
in the world will not help. I'm clocking 2 minutes + loading the XML
file. Serialization took over 4 minutes.

Given the user 'eye-glaze' factor, I'd love to load the file in 15
seconds. I didn't think that would be out of the question. The
largest file is 60 megabytes, which can be drag-drop copied in about 5
seconds.
Hope this helps.

Always, Nicholas!
 
D

_DD

The fastest possible serialization will be from creating a custom
routine which will write binary representations of the field values to a
stream. You will have to code the routines for each type, as you will face
an overhead if you use reflection. This is what serialization "suffers"
from now.

PS: Aren't there some tricks in regard to getting normal
serialization to run faster?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top