From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA15697; Mon, 25 Nov 2002 11:33:10 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA15598 for ; Mon, 25 Nov 2002 11:33:09 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gAPAX8X29376; Mon, 25 Nov 2002 11:33:08 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA15551; Mon, 25 Nov 2002 11:33:07 +0100 (MET) Date: Mon, 25 Nov 2002 11:33:07 +0100 From: Xavier Leroy To: Cezary Kaliszyk Cc: caml-list@inria.fr Subject: Re: [Caml-list] Objects poor performance Message-ID: <20021125113306.A15145@pauillac.inria.fr> References: <20021119183857.GB15185@zodiac.mimuw.edu.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20021119183857.GB15185@zodiac.mimuw.edu.pl>; from ck189400@zodiac.mimuw.edu.pl on Tue, Nov 19, 2002 at 07:38:57PM +0100 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > 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