Uncontrolled transition management from the second AppDomain is very slow

The configuration is as follows:

  • The main application domain loads a number of unmanaged C ++ libraries from the C ++ / CLI assembly.
  • The second application domain loads these C ++ libraries, but, of course, it just grabs the descriptors of previously loaded libraries.
  • I run the exact same managed C # code in both application domains that uses unmanaged C ++ libraries.
  • The C ++ / CLI assembly contains a mixture of managed and unlisted code.

When called to unmanaged C ++ libraries from the main application domain, the cost of a managed unmanaged transition is rather small compared to the total execution cost. However, from the second application domain, which did not initially load the libraries, the cost of a managed unmanaged transition becomes significant; an order of magnitude more. I know this because I am running the ANTS performance profiler, and that is what it tells me.

There are some unmanaged static variables in the C ++ / CLI assembly, I tried to replace them when a new application domain was created, but this does not change the performance. There will be a bunch of hidden ones.

What could be here? Why should switching to a different application domain be so slow? Is there something obvious to try to improve the situation?

: , - . , . , , , . , , , , .

+6

Source: https://habr.com/ru/post/1016202/


All Articles