caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "CUOQ Pascal" <Pascal.CUOQ@cea.fr>
To: <caml-list@yquem.inria.fr>, <caml-list@yquem.inria.fr>
Subject: Modify macro and caml_initialize function
Date: Sun, 5 Dec 2010 17:02:37 +0100	[thread overview]
Message-ID: <5EFD4D7AC6265F4D9D3A849CEA92191902182AD6@LAXA.intra.cea.fr> (raw)
In-Reply-To: <20101204110006.A6F91BC57@yquem.inria.fr>

ygrek wrote:

> BTW, while we are on this topic, why the following is not in upstream yet?
>
> http://eigenclass.org/R2/writings/optimizing-caml_modify
>
> Looks like a clear win-win without drawbacks (increased code size shouldn't be significant
> cause Modify is only used in a couple of places). What do you think?

This is very interesting. Thanks for pointing it out.

I think there would be a couple of alternatives to check out
before calling the patch final
(and even so, it may always remain an outside patch,
depending on interest from OCaml maintainers).

Contrary to what is implied in that post,
Array.make does not call the Modify macro:
it calls the caml_initialize function.
If you want to make Array.make faster, there is
a simple improvement: replace the idiom below:

for (i = 0; i < size; i++) caml_initialize(&Field(res, i), init);

by a call to a single function caml_initialize_block
that factors the computation of the condition:

(Is_block (val) && Is_young (val) && Is_in_heap (fp)).

A quick "grep -3 caml_initialize byterun/*.c" 
reveals 4 (out of 5) call sites that could benefit from
the caml_initialize_block function.

In fact, this makes me wonder if, in the case of Array.map,
Array.init and so on, a workable approach could not be to
compute a few values at a time (saving them in local roots)
and write them all at once, again factoring the tests

Is_in_heap (fp)

and

caml_gc_phase == Phase_mark

The first suggestion seems to me an uniform improvement
with no downside, and it stands a slim chance of going in
someday. The second one, no so much, but it would
definitely be fun to try to make work.

Pascal


       reply	other threads:[~2010-12-05 16:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20101204110006.A6F91BC57@yquem.inria.fr>
2010-12-05 16:02 ` CUOQ Pascal [this message]
2010-12-05 16:13   ` [Caml-list] " Basile Starynkevitch
2010-12-05 16:49     ` Benedikt Meurer

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=5EFD4D7AC6265F4D9D3A849CEA92191902182AD6@LAXA.intra.cea.fr \
    --to=pascal.cuoq@cea.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).