caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jan Kybic <kybic@fel.cvut.cz>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Impact of GC on memoized algorithm
Date: 14 Apr 2005 12:27:49 +0200	[thread overview]
Message-ID: <m2r7hdzm8q.fsf@fel.cvut.cz> (raw)
In-Reply-To: <e833a390f1c0996f866f9de8575c6a93@inria.fr>

> In my experience, it is important to pay attention to the cost of the
> hashing function.  If you can avoid going through the whole structure to
> compute the hash, you'll save a lot of time.
> 
> It may also be a good idea to limit the number of cache entries, instead
> of just letting the cache grow arbitrarily large.  I've had good results
> by deleting some entries at random when the cache gets too big.

Exactly. When the cache size exceeds your real RAM, it is often
cheaper to recalculate the value instead of retrieving it from the
disk (swap).  I have good experience with deleting the oldest (by
order of creation) and cheapest-to-recalculate entries when memory
becomes scarce by alternatively filling several (linked) hash tables.
The heuristic needs monitoring the current memory consumption, the
size of the items and timing the memoized operations.

On the other hand, an exact LRU (last recently used) cache based on
doubly-linked lists did not work well for me, the cost of maintaining
the links was too high.

The best trade-off obviously depends on the size of your items and
keys, cost of recalculating the items, and on the access
pattern... Experimenting is probably unavoidable.

Jan

-- 
-------------------------------------------------------------------------
Jan Kybic <kybic@fel.cvut.cz>                       tel. +420 2 2435 5721
http://cmp.felk.cvut.cz/~kybic                      ICQ 200569450


      reply	other threads:[~2005-04-14 10:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-30  8:39 Alex Baretta
2005-03-30 12:03 ` [Caml-list] " Jon Harrop
2005-03-30 12:34   ` Alex Baretta
2005-03-30 13:09     ` Alexander S. Usov
2005-03-30 13:56       ` Marcin 'Qrczak' Kowalczyk
2005-03-30 15:03         ` Alex Baretta
2005-03-31 14:41           ` Jean-Christophe Filliatre
2005-04-11 14:22           ` Damien Doligez
2005-04-11 15:48             ` Alex Baretta
2005-04-14  9:52               ` Damien Doligez
2005-04-14 10:27                 ` Jan Kybic [this message]

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=m2r7hdzm8q.fsf@fel.cvut.cz \
    --to=kybic@fel.cvut.cz \
    --cc=caml-list@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).