Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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:

   http://pauillac.inria.fr/~xleroy/talks/tutorial-pldi98.ps.gz

- 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