XmlSerializer startup HUGE performance loss on 64bit systems

前端 未结 4 1218
长发绾君心
长发绾君心 2020-12-03 01:17

I am experiencing a really HUGE performance loss while calling a simple XmlSerializer.Deserizlize() on a class with lots of fields.

NOTE

4条回答
  •  一整个雨季
    2020-12-03 01:58

    UPDATE:

    I was able to reproduce this, investigation shows that most time was spent in JIT-compiler:

    JittingStarted: "Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderFoo", "Read2_Foo", "instance class SerializersTester.Foo"

    You can easily proof that without any profiler tool.

    • Generate *.XmlSerializers.dll via sgen for x86 and x64 targets
    • Generate native images via ngen.

    You can notice x64 generation will be much more slower in compare with x86 assembly

    The exact reason hides in x64 JIT-internals (BTW it completely different from x86) and unfortunately I don't have enough spare time to find it.

    To avoid such performance loss you can generate serializer's assembly via sgen, reference it and compile to native image via ngen during application setup on end user PC.

提交回复
热议问题