Interop (.NET 1.1) Performance Checklist
From Guidance Share
Jump to navigationJump to search
J.D. Meier, Srinath Vasireddy, Ashish Babbar, Rico Mariani, and Alex Mackman
- 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.
- 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.
- 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.
- 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.