[Mono-devel-list] Q. about implementation of serialization
Lluis Sanchez
lluis at ximian.com
Wed Oct 27 07:42:35 EDT 2004
> Hello,
>
> I have a question about Serialization.
> Serialization should trace all reachable objects (an object graph)
> from a root-object to be serialized. To determine what to serialize
> needs class information of reachable objects in the graph. How does
> it get the information? Is Serialization implemented using reflection?
> Otherwise, MONO uses internal functions to identify the information? I
> also wonder how it is doen in JVM?
Reflection is the only way you have to get information about the
structure of objects, so yes, it is implemented using reflection.
> I'm worrying that if reflection is involved for serialization, it may
> have too much performance overhead.
It is not overhead, since you can't do it in any other way. It is
possible, however, to improve performance by reducing the use of
reflection in different ways, for example:
1) by building temporary class maps that hold the exact information you
need to serialize instances (so no need to query every time which fields
are serializable, for example)
2) by generating serialization code on the fly.
When using 1 and 2 the serialization process will be faster, but it will
take more memory. There is also a startup overhead, since you need to
build the maps or generate the code.
The binary serializer is using 1 and partially 2 (uses IL generation on
serialization, but not yet on deserialization).
The XmlSerializer is using both 1 and 2. Since code generation in this
serializer is very expensive (it generates c# code on the fly, which is
compiled with mcs), to reduce the startup time the generation is delayed
until a predefined number of serialization requests are made.
Lluis.
>
> Regards,
>
> Okehee
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
More information about the Mono-devel-list
mailing list