The Salty Economist

Things I Should Have Learned in High School
posts - 56, comments - 0, trackbacks - 0

Threading and Slow COM Objects

OK, so I got my multi-threaded app up and running.
But, just one problem: It is really SLOWWWWW...
After doing a little research, I discovered this gem:

"All things being equal one of the most common causes of slower execution from one thread to another occurs when the code uses a COM object that is configured to run in a single thread apartment (STA) and meets one of the following other conditions.
It is called from a thread other than the one that instantiated it.
It is called from a thread configured to run in a multithreaded apartment (MTA).
An expensive marshaling operation most occur on each and every access to the object. 
A factor of 4x slower is a completely reasonable symptom of this issue. 
Resolving this issue will be quite difficult if you continue to use the BeginInvoke invocation mechanism.
The reason is because that mechanism uses a ThreadPool thread for execution which cannot be easily (or at all) switched to STA mode." 
From here:

Interesting.  Yes, it turns out I am using a bunch of lower level VB6 COM objects that I did not want to convert yet.
When running my functions on the main thread, they run fine with the COM objects.  Whe I create new threads and try to use them, they are very slow.  I would guess 4x is a good guess.
So, I guess I'll speand the next couple of days in conversion hell.  So Sad.

Print | posted on Tuesday, May 27, 2014 4:06 PM |

Powered by:
Powered By Subtext Powered By ASP.NET