10

I have a pretty large and complex winforms application. In an effort to reduce the startup time, I pre-generated serialization assemblies using the following batch file.

; delete any existing serialization assemblies
del *XmlSerializers.dll

; gen new serialization assemblies
for %%a in (*.dll) do sgen /assembly:%%a

; delete .deleted files (generated for assemblies which do not allow serialization)
del *.dll.deleted*

However, to my surprise, the startup time actually went up from 4.6 seconds to 6.1 seconds - a jump of 1.5 seconds. This held true whether it was a cold start or warm.

So, questions:

  1. Why does my app start slower with serialization assemblies in place?
  2. Is there a way to see via Perfmon or some other tool when the app is generating serialization assemblies?
  3. Am I generating serialization assemblies correctly?
Adam
  • 15,537
  • 2
  • 42
  • 63
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
  • unless someone knows how to turn on batch-file syntax highlighting, we'll just have to leave it as `lang-none`. – Adam Aug 14 '12 at 23:59
  • How many serializers are you generating....if a large number....maybe you could combine them with ILMerge? Are you running on 64bit Windows? Do you add references to the pre-genned serialization DLLs in your project? – Colin Smith Aug 15 '12 at 01:56
  • Can you use the /Type option to only generate the serialization code for the Type that will be serialized....rather than all public types in your DLL. – Colin Smith Aug 15 '12 at 02:02
  • 1
    Not much point at guessing at this when you can run a profiler and *know* the real answer. – Hans Passant Aug 15 '12 at 02:13
  • @HansPassant & OP on `Q# 2`. Is there any chance we could see a Red-Gate Perfmon trace image? a (code) repro would be ideal! – Jeremy Thompson Aug 15 '12 at 02:57
  • @JeremyThompson I'll gen a trace image tomorrow morning. I've been running it through Ants all day today - there is so much going on with startup (e.g. BeginInvoke and throwing things on background threads), I am having trouble discerning what exactly is taking extra time. Any idea of what I would look for in the trace? – AngryHacker Aug 15 '12 at 05:51
  • @colinsmith I am generating serializers for all my assemblies (probably unnecessary) - so about 10 assemblies. Yes, 64 bit Win7. And, yes, you are probably right - I should only do that for types that are being serialized. Part of the problem is that the code base is huge - it's difficult to see everything that will be serialized - thus my question...how can I detect when a serialization assembly is being created (and on what types). And of course, the original question is still outstanding - why is the startup slower? – AngryHacker Aug 15 '12 at 05:54
  • 1
    So are you running this WinForms app as 64bit...and you compiled as AnyCPU ? Seems to be an issue in the 64bit JITter. .... http://stackoverflow.com/questions/4137335/xmlserializer-startup-huge-performance-loss-on-64bit-systems ... Also would suggest using FusionLog, and comparing how your app behaves when run as 32bit, and when run as 64bit.....maybe even Process Explorer...and watching the .NET specific data points of the process. – Colin Smith Aug 15 '12 at 09:06
  • ....FusionLogVw will tell you if it's doing a lot of probing (for whatever reason). – Colin Smith Aug 15 '12 at 09:12

2 Answers2

1

You should profile your application to see why startup time is increasing. Perfview will be a good tool to do so.

If too much time is spent in JITtting, consider NGEN your application. If too many pages are loaded, consider using mpgo optimization if you're running under .Net 4.5

Feng Yuan
  • 709
  • 5
  • 4
0

Because .NET has to check if the signature is valid

Cole Tobin
  • 9,206
  • 15
  • 49
  • 74
  • 6
    So you are saying it is faster to generate serialization assemblies than to check for a valid signature? – AngryHacker Aug 14 '12 at 23:48
  • See, it just sounds crazy when you put it THAT way. – Winfield Trail Aug 15 '12 at 04:10
  • @Cole Is there any reference you can cite to back this up? – Peter Ritchie Aug 25 '12 at 14:54
  • @PeterRitchie If it is signed, on launch, it must be checked to see if it is valid. – Cole Tobin Aug 25 '12 at 21:00
  • @ColeJohnson and that's 1.5 seconds slower than generating serialization assemblies? – Peter Ritchie Aug 25 '12 at 21:57
  • Especially considering there's so many other references that suggest pre-generation should be faster: http://msdn.microsoft.com/en-us/library/aa751883.aspx http://msdn.microsoft.com/en-us/library/ee704594.aspx http://blogs.msdn.com/b/billwert/archive/2008/02/23/use-of-sgen-exe-to-avoid-common-xmlserializer-performance-pitfalls.aspx – Peter Ritchie Aug 25 '12 at 22:01