Slow COM interop with suspiciously high "#Link Time Checks" counts

From: Ergun (Ergun_at_discussions.microsoft.com)
Date: 12/14/04


Date: Mon, 13 Dec 2004 20:05:03 -0800

I have a C#.NET application (.NET fwk 1.1) accessing Microsoft Word 9.0
Object Library through COM interop. This application performes well (600ms)
on some machines or poorly (6000ms, i.e. 10 X slower) on others, and this
happens accross all Word COM calls. In a nutshell the application renders a
100 row table and colorizes some rows or cells using code like:

         Word._Document doc = (Word._Document)rc.Document;

         Word.Range range = (Word.Range)rc.Range.Range;
         
         Word.Table wt = null;

            wt = range.ConvertToTable(
               ref seperator,
               ref numrows,
               ref numcols,
               ref initialcolwidth,
               ref format,
               ref applyBorders, // Apply borders
               ref applyShading, // Apply Shading
               ref applyFont, // Apply Font
               ref applyColor, // Apply Color
               ref applyHeading, // Apply Heading Rows
               ref falseVal, // Apply Last Row
               ref falseVal, // Apply First Column
               ref falseVal, // Apply Last Column
               ref falseVal, // AutoFit
               ref afitbvor, // AutoFit Behaviour
               ref tabbvor ); // Default Table Behaviour

            wt.Select();
            Word.Selection sel = doc.Application.Selection;

           sel.Tables.Item(1).Cell( 1, 1).Select();
           sel.SelectRow();
           sel.Cells.Shading.BackgroundPatternColor = (Word.WdColor)par.Color;

Great care was spent to make the code efficient using word table rendering
techniques given in MVP site :

(http://word.mvps.org/FAQs/TblsFldsFms/FastTables.htm).

Stopping disabling the Virus check program or various other services by
elimination didn't make any difference.

I have observed good performance on two machines so far : my home pc, and a
pc installed on an isolated test domain. All other three machines are
connected to the same business domain and performed poorly; they all have
Windows XP Service Pack2, Office 2000 and .NET Framework 1.1 installed.
During tests I made sure that all test machines have sufficient memory and
cpu resources.

I inspected ".NET CLR Security" performance object counters during my tests.
"#Link Time Checks" and "Total Runtime checks" counters had considerably
higher values on poorly performing machines than good ones.

All my assemblies are private and they are stored on (non-shared) local
drives.

Used SuppressUnmanagedCodeSecurityAttribute in the Interop libraries (i.e.
built with tlbimp /unsafe switch) as shown below:

tlbimp "C:\Program Files\Microsoft Office\Office\MSWORD9.OLB"
/namespace:Word /out:Interop.Word.dll /unsafe
tlbimp "C:\Program Files\Microsoft Office\Office\MSO9.DLL" /namespace:Office
/out:Interop.Office.dll /unsafe
tlbimp "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"
/namespace:VBIDE /out:Interop.VBIDE.dll /unsafe

Thanks very much in advance..

-- 
Regards
8-)
Ergun Çoruh
Integrated Research L
Principal Software Engineer
N.Sydney, Australia.

Quantcast