Addin activation is really slow

Dec 22, 2008 at 11:52 PM
Hi
I've been experimenting a bit with the System Addin stuff (using VS2008, MFC 9, C++ and the amazing /CLR switch) and I'm finally getting there.
I did some tests using the Stopwatch class to find out how quick the main addin operations are, and here are my results.

Time taken to... Time
create an appdomain 128ms
rebuild the addin cache 2004ms
update the addin cache 27ms
find all addins 2ms
find information about an addin 0ms
load (activate) an addin 2485ms
call a simple function in an addin 1ms
unload a plugin's appdomain 612ms

(It might be worth mentioning that I'm running on an Intel Core Duo 2x2GHz machine, I have a basic wizard-generated MFC host and a basic wizard-generated MFC addin DLL. The addin is in a "Plugins" subfolder of the app directory, the pipeline is in a "Pipeline" subfolder of the app directory, and HostView.dll is in the app directory. Everything is in Release mode and the addin is being loaded into a new appdomain with the default environment/security)

So you can see that a complete rebuild of the addin cache takes just over 2 seconds, but that will only happen on very rare occasions, so I'm not bothered about that one.

The really worrying number there is 2485ms to activate an addin. Why do you think this is taking so long? And that's with the simplest addin ever. If you've got four or five of these, or maybe 20 or 30 (which will probably be likely in my case), you're in big trouble.

Cheers
[d3m0n]
Dec 23, 2008 at 11:03 AM
I read somewhere that measuring performance under the VS debugger is a bad idea, so I tried again using Ctrl+F5.
This improved things drastically, but I think it's still too slow if you've got a decent number of addins.

Time taken to... Time
create an appdomain 5ms
rebuild the addin cache 320ms
update the addin cache 25ms
find all addins 1ms
find information about an addin 0ms
load (activate) an addin 544ms
call a simple function in an addin 0ms
unload a plugin's appdomain 16ms

I tried setting the LoaderOptimization of the new appdomain to MultiDomain but this did not affect the performance at all. And I couldn't figure out how to change the LoaderOptimization of the main appdomain, because I haven't got a "main" function - the entrypoint is wWinMainCRTStartup.

There's got to be some way of speeding it up...
Dec 23, 2008 at 12:00 PM
Just for laughs I tried doing the same thing in C#. The difference was astonishing...
(C# L.O. means with the Loader Optimization attribute set to MultiDomain)

Time taken to... MFC C# C# L.O.
create an appdomain 5ms 26ms 27ms
rebuild the addin cache  320ms  302ms 136ms
update the addin cache 25ms 23ms 22ms
find all addins 1ms 1ms 1ms
find information about an addin 0ms 0ms 0ms
load (activate) an addin 544ms 229ms 172ms
call a simple function in an addin 0ms 0ms 1ms
unload a plugin's appdomain 16ms 0ms 0ms

So there you have it. My goal is to load an MFC addin in less than 200ms.
So I need to use the MultiDomain LoaderOptimization in MFC. But how??