none
Why would using CType or DirectCast make a line of code take 10 times LONGER than late binding when accessing a COM object? RRS feed

  • Question

  • I'm using VB.NET to automate the Pro/Engineer CAD program through a COM .dll provided by the creator of Pro/Engineer. I was having problems with a certain part of my code taking much longer than expected (about 15 seconds to read the parameters of a CAD drawing). I tried switching from using CType or DirectCast (both of which had about the same performance) to turning off Option Strict and using late binding and it now takes under a second. (Nothing else changed in the code. I simply removed the early bindings.) It was my understanding that early binding was supposed to have significantly better performance. Could this have something to do with the code in the .dll? Is there another type-safe, Option Strict on possibilty which might have better performance? I hate to have to turn Option Strict off, but the slowness of the early binding in this case is simply unacceptable.

    If it's relevant, the types in question are interfaces.
    Monday, January 5, 2009 2:59 PM

Answers

  • Late binding is normally about 10,000 times slower.  I can't think of a scenario where it could be 15 times faster.
    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, January 9, 2009 12:21 PM
    Tuesday, January 6, 2009 1:41 AM
    Moderator