Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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 Archives:
Bug reports: FAQ:
Beginner's list: