Interop (.NET 1.1) Performance Checklist

From Guidance Share

Jump to: navigation, search

J.D. Meier, Srinath Vasireddy, Ashish Babbar, Rico Mariani, and Alex Mackman

Contents

Design Considerations

  • Design chunky interfaces to avoid round trips.
  • Reduce round trips with a facade.
  • Implement IDisposable if you hold unmanaged resources across client calls.
  • Reduce or avoid the use of late binding and reflection.

Marshaling

  • Explicitly name the target method you call.
  • Use blittable types where possible.
  • Avoid Unicode to ANSI conversions where possible.
  • Use IntPtr for manual marshaling.
  • Use [in] and [out] to avoid unnecessary marshaling.
  • Avoid aggressive pinning of short-lived objects.

Marshal.ReleaseCOMObject

  • Consider calling ReleaseComObject in server applications.
  • Do not force garbage collections with GC.Collect.

Code Access Security (CAS)

  • Consider using SuppressUnmanagedCode for performance-critical, trusted scenarios.
  • Consider using TLBIMP /unsafe for performance-critical, trusted scenarios.

Threading

  • Reduce or avoid cross-apartment calls.
  • Use ASPCOMPAT when you call single-threaded apartment (STA) objects from ASP.NET.
  • Use MTAThread when you call free-threaded objects.
  • Avoid thread switches by using Neutral apartment COM components.

Monitoring Interop Performance

  • Use performance counters for P/Invoke and COM interop.
  • Use CLR Spy to identify interop problems.

Resources

Personal tools