Browse thread
Execution time of class versus record
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Arnaud Spiwack <aspiwack@l...> |
| Subject: | Re: [Caml-list] Execution time of class versus record |
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 <jon@ffconsultancy.com> 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
>>
>
>