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] Objects poor performance
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-11-25 (10:33)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Objects poor performance
> I tried to implement a simple double-linked list with constant time
> insertion and removal. I tried just iterating over such a list with
> both object and structure implementation. And these are the effects:
>              Time:
> Structures:  2.503s
> Objects:    27.027s
> The implementations are the same so why are objects that slow?

Two reasons:

1- With the object encoding, accesses to the "prev" and "next" field
of each list cell goes through a method invocation, while in the
function encoding these are just direct accesses to record fields
(much cheaper).

2- Method invocations are always compiled down to an indirect
(computed) function call, while most function calls are optimized to
direct (static) function calls. or even inlined.  Indirect calls are
about 10 times more expensive than direct calls on modern processors.
For more info on this topic, see my PLDI'98 tutorial:


- 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