caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Arnaud Spiwack <aspiwack@lix.polytechnique.fr>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Execution time of class versus record
Date: Mon, 25 Jun 2007 04:18:55 +1000	[thread overview]
Message-ID: <1182709135.6233.13.camel@rosella.wigram> (raw)
In-Reply-To: <467E9676.50905@lix.polytechnique.fr>

On Sun, 2007-06-24 at 18:06 +0200, Arnaud Spiwack wrote:
> Which obviously raises the question: What is the motivation for the 
> object to be encoded differently than records? 

Someone with more expertise will assuredly correct me,
but this is my picture:

Ocaml objects can be accessed via a class type.

An object matches a type if it has the required methods,
matched by name and type (structural typing).

For a given class type, objects of different types might match, 
so there has to be a lookup table mapping the method of the call
to the method of the object.

Therefore, the indirection is unavoidable. But why can't
we use an array, indexed by the method number?

This would be possible. However consider a coercion
from a class type to a supertype: the supertype might
have less methods, or methods in a different order.
So the coercion would require dynamically building a new
method array.

On the other hand with a dictionary, the method lookup
is slower, but the same dictionary can be used for the 
supertype, since statically, you can only lookup a method
that is sure to be in the subtype .. the other methods
of the subtype simply won't be found.

The dictionary of an object is known statically at construction
time so it can be created once on program initialisation.

This means: construction and coercion are fast, the dictionary
is already built. Lookup is slower than optimal. And finally,
the dictionary method is easier for the compiler writers:
just store the dictionary in the object.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


  reply	other threads:[~2007-06-24 18:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-24 15:14 tmp123
2007-06-24 15:29 ` [Caml-list] " Jon Harrop
2007-06-24 15:48   ` Till Varoquaux
2007-06-24 16:06     ` Arnaud Spiwack
2007-06-24 18:18       ` skaller [this message]
2007-06-24 18:29       ` Gerd Stolpmann
2007-06-24 18:51         ` Arnaud Spiwack
2007-06-24 19:11           ` Chris King
2007-06-25  3:25           ` Jon Harrop
2007-06-25 11:16             ` Arnaud Spiwack
2007-06-25 12:07               ` Jon Harrop
2007-06-25 23:59                 ` Jonathan Bryant
2007-06-26  0:15                   ` Chris King
2007-06-26  6:53                     ` Loup Vaillant
2007-06-26  7:02                       ` Jon Harrop
2007-06-26 17:07                         ` Loup Vaillant
2007-06-28  1:13                 ` Christian Stork
2007-06-26 13:35 ` Sam Steingold
2007-06-26 16:29   ` [Caml-list] " Quôc Peyrot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1182709135.6233.13.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=aspiwack@lix.polytechnique.fr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).