Pages

Monday, April 2, 2012

Quick Tip: Custom Component Performance

As regular readers will know, I've got a few custom components for SQL Server Integration Services under my belt, some of which I've published at CodePlex.  As I was working with one of the components I haven't published, I got a little frustrated with the length of time it was taking the UI to appear when I'd double-clicked it, as well as the length of time it took to return to the design surface after accepting my changes.
After a little investigation, the excessive time could be traced to a single type of operation that occurs several times in this component inside the Validate and ReinitializeMetaData methods.  It's quite a common thing to do - so if you happen to have created any components for SSIS, I suggest you read on .
What's Slow?
The performance drag?  Iterating over IDTSInputColumnCollections and IDTSOutputColumnCollections.  Probably a no-brainer for you knowledgeable COM interop experts out there - but iterating over those collections is slow.
Where's the Nitrous?
To avoid those iterations, I constructed my own "temporary" collection(s) with the same elements to iterate over instead.  In some cases I used a Hashtable (keyed by column name or lineage ID), and in some cases a simple List was just fine.  I still incurred one performance hit in building my temporary collection - because I had to iterate over the COM collection once.  After that, smooth sailing and a huge performance increase.
Warning...
Do be a little careful though!  Creating a temporary collection to "mirror" the built-in one is perfectly safe when in the Validation context, because nothing is permitted to change.  However, you have to watch your own code and the "staleness" of your collection in the ReinitializeMetaData context.  Both you and SSIS can be altering the input and output collections at this time.  So if you're playing with the UsageType on inputs, or adding or removing columns from asynchronous outputs, you'll have to make similar adjustments to your temporary collections or they'll get out of sync.

No comments:

Post a Comment