Feb 212008

Charlie Calvert writes about dynamic method invocation that has been implemented in the .NET DLR and is working its way into getting proper support by the full VS.NET tool set.  Dynamic method invocation is late binding to the extreme – the lookup is performed at runtime, every time the function call executes.  The compiler has no idea whether the function you’re referring to exists at compile time, so it emits code to make the lookup and call the address with a hope and a prayer.

Hey!  It’s Delphi Variants all over again!  ;>  In Delphi Win32, you can assign an IDispatch COM interface to a Variant, and then make method calls using that variant.  The method calls were reduced by the compiler to a call to GetIDsOfNames, passing the method name in as a string param, and then a call to Invoke, passing the explicit arguments wrapped up in Variants.

Dynamic invoke is certainly a powerful construct for dynamic languages, but it is oft maligned by compiled languages for inherent performance problems and nail-biting ambiguity.  For JavaScript, ambiguity is the source of its seductive dark power.  In the highly structured, explicit, dare I say predictable universe of Delphi syntax, late-binding ambiguity is the entropy engine of insanity.

  4 Responses to “C# Future Focus: Delphi History Repeating”

  1. The ambiguity isn’t going away, but the performance shouldn’t suffer *too* much – polymorphic inlining should minimize the costs. If a delegate referencing a DynamicMethod with signature matching the actual type of the arguments is generated, there shouldn’t even be too much in the way of argument marshalling costs.

    Of course, push one end and it comes out the other: there’ll be memory and cold-start costs…

  2. Hi Barry,

    True, argument matching and prefetch do help mitigate the call overhead, but it’s still a far cry from a statically compiled call. The address of the destination is right there in the machine code stream, and can be prefetched and branch predicted all day long.

    Keep in mind that the performance nuts that wail about dynamic dispatch are often the same ones that complain about the performance cost of indirect calls for virtual methods compared to static calls. ;>

    Thanks for the feedback!


  3. […] 2008. Charlie Calvert writes about dynamic method invocation that has been implemented in the . …http://dannythorpe.com/2008/02/21/c-future-focus-delphi-history-repeating/Your future: Delphi OCTANEYour future: delphi OCTANE … delphi OCTANE :: Interested in the next […]

  4. […] vienen recuerdos de aquellos tiempos: con la nueva palabra reservada dynamic, me parece (y creo que no solo a mí) que C# está repitiendo la historia de Delphi. Publicado el lunes, 22 de diciembre de 2008 15:00 […]

Sorry, the comment form is closed at this time.