English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Object-oriented access bottleneck
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-12-08 (19:02)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Object-oriented access bottleneck
> How much slower is a member function call compared to a non-member 
> function call?  I was given the impression that it was signifigantly 
> slower, but you're making it sound like it isn't.

In the non-member case, it depends very much whether the function
being called is statically known or is computed at run-time.  In the
first case, a call to a static address is generated.  In the latter
case, a call to a function pointer is generated.

Here are some figures I collected circa 1998 on a PowerPC 603 processor:

   type of call              cost of call

inlined function               0 cycles
call to known function         4 cycles
call to unknown function      11 cycles
method invocation             18 cycles

I'm pretty sure that more modern processors have a bigger gap between
the "call to known function" and "call to unknown function" cases.

So, as you can see, method invocation isn't much more expensive than a
call to an unknown function, but is significantly more expensive than
a call to a known function.  

In source-level terms, replacing an object by a record of functions
isn't going to make a major performance difference (the applications
of the functions fetched from the record fall in the "call to unknown
function" case), while getting rid of dynamic dispatch entirely and
just call known functions is a much bigger improvement.

Hope this clarifies the issue.

- Xavier Leroy

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners