reflection emit slows down the more I use it

  • Thread starter Thread starter Ben Voigt
  • Start date Start date
B

Ben Voigt

I've written a converter from ASN.1 type descriptions to .NET structures
(well, with a perl front-end that creates intermediate XML, I think the XML
is useful in its own right). There are over 250 types being converted.

The output looks great viewed from .NET Reflector. However, I'm having
performance problems with the conversion itself. Initially, it runs through
types very quickly (5-6 per second). By the end of the run it is consuming
100% of one logical CPU (Hyperthreading) for nearly 30 seconds in each call
to TypeBuilder.CreateType().

Is CreateType doing searches or something that makes it O(N) or worse in the
number of types in the dynamic module? I tried to free up each TypeBuilder
after calling CreateType but that didn't seem to help.

The types being emitted are all pretty much the same complexity
throughout...

Does anyone know what is causing this performance hit and any possible
solution?
 
Ben Voigt said:
I've written a converter from ASN.1 type descriptions to .NET structures
(well, with a perl front-end that creates intermediate XML, I think the
XML is useful in its own right). There are over 250 types being
converted.

The output looks great viewed from .NET Reflector. However, I'm having
performance problems with the conversion itself. Initially, it runs
through types very quickly (5-6 per second). By the end of the run it is
consuming 100% of one logical CPU (Hyperthreading) for nearly 30 seconds
in each call to TypeBuilder.CreateType().

Is CreateType doing searches or something that makes it O(N) or worse in
the number of types in the dynamic module? I tried to free up each
TypeBuilder after calling CreateType but that didn't seem to help.

The types being emitted are all pretty much the same complexity
throughout...

Does anyone know what is causing this performance hit and any possible
solution?

Found out it's the Visual Studio debugger... when I start without debugging
it runs smoothly. Doesn't matter whether it's a release (optimized) build,
only that the debugger is attached. I guess the Visual Studio debugger must
be loading type information for emitted assemblies, each time CreateType is
called, and must be reprocessing the entire assembly. Since types can't
change after CreateType is called, it should only be necessary to process
the newly created type, maybe be caching the data for all the other
dynamically created types.... Also splitting it into separate dynamic
modules doesn't make any difference.
 
Back
Top