A
Adam Benson
Hi,
We sometimes have to send large numbers (about 4000) of small items from
client to server and back again.
We manually serialize and deserialize using BinaryFormatter and profiling
shows two things:
1) Using a SerializationInfoEnumerator in the deserialization constructor is
much faster than specifically reading each field.
i.e. this pattern
SerializationInfoEnumerator sie = info.GetEnumerator();
while (sie.MoveNext())
{
o = sie.Current.Value;
objname = sie.Current.Name;
switch (objname)
{
case "B1": tooltip = (string)o;
break;
case "B2": clipTypeColour = Color.FromArgb((int)o);
break;
...
}
}
is much faster than this
this.tooltip = info.GetString("B1");
this.clipTypeColour = info.Get .... etc etc
2) ObjectReader.Deserialize seems to spend 1/4 of its time in DoFixups,
which ends up calling our deserialization constructors. But 3/4 of its time
is spent in Run. My guess is that Run builds a map of all that's available
including a map of names to objects.
So, my question is, is it possible to call BinaryFormatter.Deserialize in
such a way that it does not build a map of object names to values on the
grounds that we will just enumerate through it all using a
SerializationInfoEnumerator? I suspect if we could do that we would see a
huge leap in performance.
Of course, it may not be possible, and my question may reflect my ignorance
of what's really going on.
Thanks for any info,
- Adam.
==============================
(e-mail address removed)
We sometimes have to send large numbers (about 4000) of small items from
client to server and back again.
We manually serialize and deserialize using BinaryFormatter and profiling
shows two things:
1) Using a SerializationInfoEnumerator in the deserialization constructor is
much faster than specifically reading each field.
i.e. this pattern
SerializationInfoEnumerator sie = info.GetEnumerator();
while (sie.MoveNext())
{
o = sie.Current.Value;
objname = sie.Current.Name;
switch (objname)
{
case "B1": tooltip = (string)o;
break;
case "B2": clipTypeColour = Color.FromArgb((int)o);
break;
...
}
}
is much faster than this
this.tooltip = info.GetString("B1");
this.clipTypeColour = info.Get .... etc etc
2) ObjectReader.Deserialize seems to spend 1/4 of its time in DoFixups,
which ends up calling our deserialization constructors. But 3/4 of its time
is spent in Run. My guess is that Run builds a map of all that's available
including a map of names to objects.
So, my question is, is it possible to call BinaryFormatter.Deserialize in
such a way that it does not build a map of object names to values on the
grounds that we will just enumerate through it all using a
SerializationInfoEnumerator? I suspect if we could do that we would see a
huge leap in performance.
Of course, it may not be possible, and my question may reflect my ignorance
of what's really going on.
Thanks for any info,
- Adam.
==============================
(e-mail address removed)