Prescriptive Architecture
Checklist: Interop Performance
 

Patterns and Practices home

Improving .NET Application Performance and Scalability

J.D. Meier, Srinath Vasireddy, Ashish Babbar, and Alex Mackman
Microsoft Corporation

May 2004

Related Links

Home Page for Improving .NET Application Performance and Scalability

Send feedback to Scale@microsoft.com

patterns & practices Library

How to Use This Checklist

This checklist is a companion to Chapter 7, "Improving Interop Performance"

Design Considerations

CheckDescription
ms978943.checkbox(en-us,MSDN.10).gifDesign chunky interfaces to avoid round trips.
ms978943.checkbox(en-us,MSDN.10).gifReduce round trips with a facade.
ms978943.checkbox(en-us,MSDN.10).gifImplement IDisposable if you hold unmanaged resources across client calls.
ms978943.checkbox(en-us,MSDN.10).gifReduce or avoid the use of late binding and reflection.

Marshaling

CheckDescription
ms978943.checkbox(en-us,MSDN.10).gifExplicitly name the target method you call.
ms978943.checkbox(en-us,MSDN.10).gifUse blittable types where possible.
ms978943.checkbox(en-us,MSDN.10).gifAvoid Unicode to ANSI conversions where possible.
ms978943.checkbox(en-us,MSDN.10).gifUse IntPtr for manual marshaling.
ms978943.checkbox(en-us,MSDN.10).gifUse [in] and [out] to avoid unnecessary marshaling.
ms978943.checkbox(en-us,MSDN.10).gifAvoid aggressive pinning of short-lived objects.

Marshal.ReleaseCOMObject

CheckDescription
ms978943.checkbox(en-us,MSDN.10).gifConsider calling ReleaseComObject in server applications.
ms978943.checkbox(en-us,MSDN.10).gifDo not force garbage collections with GC.Collect.

Code Access Security (CAS)

CheckDescription
ms978943.checkbox(en-us,MSDN.10).gifConsider using SuppressUnmanagedCode for performance-critical, trusted scenarios.
ms978943.checkbox(en-us,MSDN.10).gifConsider using TLBIMP /unsafe for performance-critical, trusted scenarios.

Threading

CheckDescription
ms978943.checkbox(en-us,MSDN.10).gifReduce or avoid cross-apartment calls.
ms978943.checkbox(en-us,MSDN.10).gifUse ASPCOMPAT when you call single-threaded apartment (STA) objects from ASP.NET.
ms978943.checkbox(en-us,MSDN.10).gifUse MTAThread when you call free-threaded objects.
ms978943.checkbox(en-us,MSDN.10).gifAvoid thread switches by using Neutral apartment COM components.

Monitoring Interop Performance

CheckDescription
ms978943.checkbox(en-us,MSDN.10).gifUse performance counters for P/Invoke and COM interop.
ms978943.checkbox(en-us,MSDN.10).gifUse CLR Spy to identify interop problems.

Patterns and Practices home

Page view tracker