views:

86

answers:

1

I've read that assembly serialization (sgen.exe) can improve performance. What exactly is providing the improvement? Is it metadata on the Types? I would have thought this would be available through reflection! so why is it required in a separate assembly?

+1  A: 

The serialization assemblies Data.XmlSerializers.dll which improve the performance of clients that use XML Web service proxies to communicate with servers is described under http://msdn.microsoft.com/en-us/library/bk3w6240.aspx.

If you don't do this the same work will be done at the first usage of XmlSerializer. In the blog http://blogs.msdn.com/b/billwert/archive/2008/02/23/use-of-sgen-exe-to-avoid-common-xmlserializer-performance-pitfalls.aspx is described additional setting in <system.diagnostics> area of the application.config file to see more what do XmlSerializer in the background.

In Visual Studio there are a spetion setting in the "Build" tab of project settings (see http://www.eggheadcafe.com/tutorials/aspnet/8eb0e68f-5496-4363-9cb9-dd68447ba187/xml-serializer-generator.aspx). So you not really need to use sgen.exe manually.

To more understand what sgen.exe do you can load an open source version of sgen.exe: xgenplus http://xgenplus.codeplex.com/.

I recommend you aslo to read http://stackoverflow.com/questions/2543641/sgen-xmlserializer-should-be-xmlserializers-dll-added-as-a-reference-to-the-cu.

If you search in google for XmlSerializer and sgen you will find all the information and even more on the first page of the serch results.

Oleg
Oleg, thanks for the detailed response, unfortunately it doesn't answer my question, I'm not asking what serialization is but why is it how does serializing your assembly improve performance?The context is a desktop application and not web.How is a pre serialization assembly improving the clr performance?Thanks.
learnerplates
In links which I posted you can read that the implementation of `XmlSerializer` need such kind of assembly. At the first use of `XmlSerializer` it verify if the assembly not exist it create it in the TEMP directory. This takes much time. If `XmlSerializer` find a pre-created assembly it use it and your program works quickly. Are you agree?
Oleg
The article isn't clear"When you use an XmlSerializer, a helper assembly(1) with a custom type for serializing your type is created. The C# CodeDom is used to generate this code, which then is compiled by the C# compiler. The runtime must then load this generated assembly, and JIT the code. .........."Does this mean that the CLR always uses the XMLSerializer when loading assemblies? and then the steps mentioned above occur.If so that's what I'm looking for. the CLR tries to serialize the assembly being loaded, if one already exists then it uses that serialized assembly instead.
learnerplates
I think that you correct understand now. Your program will either use assemblies which you created with respect of sgen.exe of a project settings or your your program will do the same work (generate the corresponding assembly in %TEMP% directory and then use it) dynamically. You use all time "to serialize the assembly" which is wrong. Correct is "serialization assembly", but these are only words. Important only to understand how your program, which used `XmlSerializer`, really works.
Oleg
lovely Oleg. That's what I was looking for.Cheers.
learnerplates