caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] local root registration
@ 2002-02-22 12:06 Winfried Dreckmann
  2002-02-22 14:27 ` Markus Mottl
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Winfried Dreckmann @ 2002-02-22 12:06 UTC (permalink / raw)
  To: € caml list

Dear Caml-list,

Some time ago, Xavier Leroy wrote:

> We've been through several designs for the "local root registration" API.
> The CAMLxxx macros are the latest design, and the one that we think is
> the easiest to use.

I agree that they are easiest if one strictly follows the rules in the
documentation. However, I would like to point out that there are cases where
one does not want to do this. In these cases, the older macros (Begin_roots
and End_roots) are much more flexible, and can even lead to better code.

I will discuss this a little. Perhaps the Begin_roots/End_roots macros
should not be deprecated, but left as a low level alternative? In one case
the documentation already differs between a simple and a low level
interface, and I believe this is a good approach. What do other list members
think?

I am thinking of cases, where one uses resizable blocks, which are only
occasionally resized, while usually nothing gets allocated. A good example
is Michel Quercia's "Numerix". He has resizable big integers, and of course
wants to save every cpu cycle for crucial arithmetic operations when
allocation does not occur. His approach is to surround the allocators and
resizers by Begin_roots/End_roots macros, e. g.

#define Enlarge_1_1(a,l,b) {             \
  if (Capacity(a) < (l)) {               \
    Begin_roots2(a,b);                   \
    New(a,0,2*(l)+1);                    \
    End_roots2(a,b);                     \
  }                                      \
}

(see "lib/common/ml-alloc.h" in the numerix distribution). In this way, the
price for garbage collection is only paid if allocation actually takes
place. It seems impossible to achieve the same effect with CAMLxxx macros.

Winfried Dreckmann

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] local root registration
  2002-02-22 12:06 [Caml-list] local root registration Winfried Dreckmann
@ 2002-02-22 14:27 ` Markus Mottl
  2002-02-22 18:10   ` Winfried Dreckmann
  2002-02-24 17:28 ` Xavier Leroy
  2002-02-24 17:58 ` Michel Quercia
  2 siblings, 1 reply; 5+ messages in thread
From: Markus Mottl @ 2002-02-22 14:27 UTC (permalink / raw)
  To: Winfried Dreckmann; +Cc: OCAML

On Fri, 22 Feb 2002, Winfried Dreckmann wrote:
> I agree that they are easiest if one strictly follows the rules in the
> documentation. However, I would like to point out that there are cases
> where one does not want to do this. In these cases, the older macros
> (Begin_roots and End_roots) are much more flexible, and can even lead
> to better code.

Yes, to me they also seem more approriate at times.

> I will discuss this a little. Perhaps the Begin_roots/End_roots macros
> should not be deprecated, but left as a low level alternative?

I can't remember that there were intentions to remove them. They rather
seem to be discouraged in favour of the new scheme whenever the latter
can be applied without tradeoffs.

> In one case the documentation already differs between a simple and a
> low level interface, and I believe this is a good approach. What do
> other list members think?

There should certainly be an efficient way to conditionally protect
roots, which cannot be done with the new macro scheme. Furthermore,
to my knowledge there is currently no way to allocate and raise more
complex exceptions with "mlraise" without using the older macros.

> (see "lib/common/ml-alloc.h" in the numerix distribution). In this way,
> the price for garbage collection is only paid if allocation actually
> takes place. It seems impossible to achieve the same effect with
> CAMLxxx macros.

If I am not seriously mistaken, only allocations on the OCaml-heap can
trigger a collection. There is just a small overhead associated with
(un)registering OCaml-values as reachable, but it's certainly a good idea
to remove every kind of unnecessary overhead in performance-critical code.

Regards,
Markus Mottl

-- 
Markus Mottl                                             markus@oefai.at
Austrian Research Institute
for Artificial Intelligence                  http://www.oefai.at/~markus
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] local root registration
  2002-02-22 14:27 ` Markus Mottl
@ 2002-02-22 18:10   ` Winfried Dreckmann
  0 siblings, 0 replies; 5+ messages in thread
From: Winfried Dreckmann @ 2002-02-22 18:10 UTC (permalink / raw)
  To: Markus Mottl; +Cc: € caml list

on 22.02.2002 15:27 Uhr, Markus Mottl at markus@oefai.at wrote:

> I can't remember that there were intentions to remove them. They rather
> seem to be discouraged in favour of the new scheme whenever the latter
> can be applied without tradeoffs.

Yes. Maybe I misinterprete "supersede" in the documentation.

> There should certainly be an efficient way to conditionally protect
> roots, which cannot be done with the new macro scheme.

That's what I mean. Thank you for expressing it in a few words.

>> (see "lib/common/ml-alloc.h" in the numerix distribution). In this way,
>> the price for garbage collection is only paid if allocation actually
>> takes place. It seems impossible to achieve the same effect with
>> CAMLxxx macros.
> 
> If I am not seriously mistaken, only allocations on the OCaml-heap can
> trigger a collection. There is just a small overhead associated with
> (un)registering OCaml-values as reachable, but it's certainly a good idea
> to remove every kind of unnecessary overhead in performance-critical code.

I should have written "the price for registering is only paid if ...". Yes,
the Ocaml interface for Numerix allocates on the Ocaml heap. Yes, the
overhead would be small. But in some cases (lots of operations on "small"
big integers) this makes a difference.

Regards,
Winfried Dreckmann

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] local root registration
  2002-02-22 12:06 [Caml-list] local root registration Winfried Dreckmann
  2002-02-22 14:27 ` Markus Mottl
@ 2002-02-24 17:28 ` Xavier Leroy
  2002-02-24 17:58 ` Michel Quercia
  2 siblings, 0 replies; 5+ messages in thread
From: Xavier Leroy @ 2002-02-24 17:28 UTC (permalink / raw)
  To: Winfried Dreckmann; +Cc: € caml list

> > We've been through several designs for the "local root registration" API.
> > The CAMLxxx macros are the latest design, and the one that we think is
> > the easiest to use.
> 
> I agree that they are easiest if one strictly follows the rules in the
> documentation. However, I would like to point out that there are cases where
> one does not want to do this. In these cases, the older macros (Begin_roots
> and End_roots) are much more flexible, and can even lead to better code.

I agree there are cases where root registration is required only on
rarely-executed paths, and in this case Begin_roots/End_roots allow
avoiding the cost of root registration on other paths.  I haven't
measured how much speed is gained this way.  Probably not much, since
GC root registration is relatively simple.

> I will discuss this a little. Perhaps the Begin_roots/End_roots macros
> should not be deprecated, but left as a low level alternative?

Begin_roots/End_roots will remain defined for a long time, if only
because I still have some old code that use these macros, and (as
regulars on this list know) I don't like gratuitous breaking of old
code.

The only problem with documenting them as a low-level alternative to
CAMLparam is that the chapter "Interfacing Caml with C" of the
documentation is already huge and quite hard to read!  Perhaps a
different organization of this chapter (e.g. a separate chapter for
"Advanced topics in interfacing Caml with C") is in order.

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] local root registration
  2002-02-22 12:06 [Caml-list] local root registration Winfried Dreckmann
  2002-02-22 14:27 ` Markus Mottl
  2002-02-24 17:28 ` Xavier Leroy
@ 2002-02-24 17:58 ` Michel Quercia
  2 siblings, 0 replies; 5+ messages in thread
From: Michel Quercia @ 2002-02-24 17:58 UTC (permalink / raw)
  To: caml-list

Le Fri, 22 Feb 2002 13:06:16 +0100
Winfried Dreckmann <wd@lidingo.mail.telia.com> écrivit :

> I am thinking of cases, where one uses resizable blocks, which are only
> occasionally resized, while usually nothing gets allocated. A good
> example is Michel Quercia's "Numerix"...

Le Fri, 22 Feb 2002 15:27:41 +0100
Markus Mottl <markus@oefai.at> écrivit :

> If I am not seriously mistaken, only allocations on the OCaml-heap can
> trigger a collection. There is just a small overhead associated with
> (un)registering OCaml-values as reachable, but it's certainly a good
> idea to remove every kind of unnecessary overhead in
> performance-critical code.

You are both right, the main reason for protecting begin_roots/end_roots
calls behind a capacity check in Numerix is speed performance, especially
for mutable big integers which are designed to achieve the highest speed
that is possible. But this is not the whole story : I also had to take
into account old versions of Ocaml as well as Caml-light (still in use in
our French National Education) for which there is only
begin_roots/end_roots or push_roots/pop_roots available.

Regards,
-- 
Michel Quercia
57 rue abbé Grégoire, 38000 Grenoble
http://michel.quercia.free.fr (maths)
http://pauillac.inria.fr/~quercia (informatique)
mailto:michel.quercia@prepas.org
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-02-24 17:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-22 12:06 [Caml-list] local root registration Winfried Dreckmann
2002-02-22 14:27 ` Markus Mottl
2002-02-22 18:10   ` Winfried Dreckmann
2002-02-24 17:28 ` Xavier Leroy
2002-02-24 17:58 ` Michel Quercia

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).