From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=AWL,MAILTO_TO_SPAM_ADDR, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 052B9BC69 for ; Sun, 24 Jun 2007 18:06:16 +0200 (CEST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.173]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5OG6FI6020582 for ; Sun, 24 Jun 2007 18:06:15 +0200 Received: by ug-out-1314.google.com with SMTP id p27so1035527ugc for ; Sun, 24 Jun 2007 09:06:15 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=C/rSMuYrEMPw91k7PjcFM79kCb6hM11PXBw2cUhLQ6YPzg32xNeT+SpcJn66kgrsPgD6x6zttDYKT1kvmFPdpSmFFTvemqU88lCswzKMOqiPN8D/HZiHxQsGjEUdnSi4nrvfN/efOtEM0ZxS83w4XHdW3J75FHIBWjw6QPuPmk0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=rCIH4gT9Pqx1STH587yeL22i5gHG1iZvE1G7PKg2DOmsQTX78+oihDv5JCEVl/XCpyglyMMVYQqOU11MJd65gVi32nTWtH2rrqqH6jdKopEM/TVmAkIY1G/4Az0WWmDt4Qsw2ty3bNgKUU9Ib3k92oNcWG0RhKVZtvJTartkySo= Received: by 10.66.239.16 with SMTP id m16mr4480986ugh.1182701174962; Sun, 24 Jun 2007 09:06:14 -0700 (PDT) Received: from ?83.248.129.218? ( [83.248.129.218]) by mx.google.com with ESMTP id j9sm3044612mue.2007.06.24.09.06.14 (version=SSLv3 cipher=RC4-MD5); Sun, 24 Jun 2007 09:06:14 -0700 (PDT) Message-ID: <467E9676.50905@lix.polytechnique.fr> Date: Sun, 24 Jun 2007 18:06:14 +0200 From: Arnaud Spiwack User-Agent: Thunderbird 2.0.0.4 (Windows/20070604) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Execution time of class versus record References: <467E8A6E.9050700@menta.net> <200706241629.50551.jon@ffconsultancy.com> <9d3ec8300706240848o6ac94a29q67f32d4774c88e0e@mail.gmail.com> In-Reply-To: <9d3ec8300706240848o6ac94a29q67f32d4774c88e0e@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Sender: Arnaud Spiwack X-Miltered: at discorde with ID 467E9677.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; lix:01 runtime:01 ocaml:01 -dlambda:01 seq:01 pervasives:01 seq:01 pervasives:01 cheers:01 ocamlopt:01 ocaml:01 beginner's:01 bug:01 frog:98 beginners:01 Which obviously raises the question: What is the motivation for the object to be encoded differently than records? I remember reading in Xavier Leroy's technical report about the first ZAM how he prepared the field for extensible records (to be able to implement objects). There the name of the fields were compiled into an adress, resulting no runtime conversion. I can imagine a couple of applications to the current situation (though I'm not so sure they would work), but I'm really interested in the original reason of this design choice. Arnaud Spiwack Till Varoquaux a écrit : > Objects in OCaml are dictionary based, which means methods names must > be looked up in a table in order to get there addresses. Record fields > on the other hand are addressed directly. Take two files test.ml and > test2.ml: > test.ml: > type b= > { > field:int > } > let a={field=1};; > print_int a.field > > test2.ml > let a=object > method field=1 > end;; > print_int a#field > > and dump there intermediate representation (-dlambda) > > test.ml > > (setglobal Test! > (let (a/61 [0: 1]) > (seq (apply (field 27 (global Pervasives!)) (field 0 a/61)) > (makeblock 0 a/61)))) > > test2.ml > > (setglobal Test2! > (let > (a/58 > (let > (class/72 (apply (field 15 (global CamlinternalOO!)) [0: > #"field"]) > obj_init/80 > (let > (field/61 > (apply (field 6 (global CamlinternalOO!)) class/72 > #"field")) > (seq > (apply (field 10 (global CamlinternalOO!)) class/72 > (makeblock 0 field/61 0a 1)) > (function env/74 > (apply (field 23 (global CamlinternalOO!)) 0a > class/72))))) > (seq (apply (field 16 (global CamlinternalOO!)) class/72) > (apply obj_init/80 0a)))) > (seq (apply (field 27 (global Pervasives!)) (send a/58 9671866)) > (makeblock 0 a/58)))) > > You can now understand where the performance issues comes from. > > Cheers, > Till > On 6/24/07, Jon Harrop wrote: >> On Sunday 24 June 2007 16:14:54 tmp123@menta.net wrote: >> > Hello, >> > >> > I've tried to implement two equivalent small programs, the one using >> > class, the other one using records. The resulting execution times says >> > that class are 7-8 times slower than record (compiled with ocamlopt >> in a >> > Intel machine). >> > >> > Please, knows someone what I'm doing wrong? >> >> You aren't doing anything wrong. >> >> -- >> Dr Jon D Harrop, Flying Frog Consultancy Ltd. >> The OCaml Journal >> http://www.ffconsultancy.com/products/ocaml_journal/?e >> >> _______________________________________________ >> Caml-list mailing list. Subscription management: >> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list >> Archives: http://caml.inria.fr >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs >> > >