Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Fergus Henderson <fjh@cs.mu.OZ.AU>
To: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr>
Cc: Chris Hecker <checker@d6.com>, caml-list@inria.fr
Subject: Re: [Caml-list] why does hashtbl not use lists?
Date: Tue, 10 Jul 2001 19:42:55 +1000	[thread overview]
Message-ID: <20010710194255.A15865@hg.cs.mu.oz.au> (raw)
In-Reply-To: <15178.50493.314895.925129@pc803>

On 10-Jul-2001, Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr> wrote:
> 
> Chris Hecker writes:
>  > 
>  > Why does hashtbl.ml (from  the standard library) use the bucketlist
>  > variant instead of just the built in lists with tuples? Is there an
>  > efficiency thing going on here?
> 
> Yes, it saves 33% of memory. Indeed, a list of tuples will give blocks
> like this:
> 
>      ______
>      |X|.|.|......>
>      ---.--     _______
>         ......> |X|a|b|
>                 -------
> 
> that is,  6 words for each  binding, whereas the  bucketlist type will
> give blocks like this:
> 
>      _________
>      |X|a|b|.|....>
>      ---------
> 
> that is, 4 words. (X stands for  the block header, which is 1 word and
> dots stand for pointers; sory for the ugly ASCII drawing).

No doubt you are right about it being 6 words vs 4 words,
rather than 4 words vs 3 words, as I said in my earlier mail;
I didn't recall that Ocaml used a header word here.

> (Beside saving  memory, you  also save time,  by allocating  one block
> instead of two  and also when destructuring the  block to look inside,
> since depth is 1 instead of 2.)

I thought about mentioning the time saving from the reduced number of
allocations, but then I wondered whether it would really save any time.
If you have a compacting garbage collector, as I'm pretty sure Ocaml does,
and a good compiler, then the compiler would be able to combine the two
allocations into a single one.  Does Ocamlopt do that?

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  reply	other threads:[~2001-07-10  9:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-10  8:34 Chris Hecker
2001-07-10  9:00 ` Fergus Henderson
2001-07-10  9:05 ` Jean-Christophe Filliatre
2001-07-10  9:42   ` Fergus Henderson [this message]
2001-07-10 14:44     ` Xavier Leroy
2001-07-10 17:04 Charles Martin

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=20010710194255.A15865@hg.cs.mu.oz.au \
    --to=fjh@cs.mu.oz.au \
    --cc=Jean-Christophe.Filliatre@lri.fr \
    --cc=caml-list@inria.fr \
    --cc=checker@d6.com \
    /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