From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 1998FBBAF for ; Sun, 5 Dec 2010 17:02:39 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkIBAL9G+0yEp8MPmWdsb2JhbACjMRUBAQEBAQgLCgcRIr0BhUkEim6DGYIA X-IronPort-AV: E=Sophos;i="4.59,302,1288566000"; d="scan'208";a="82033643" Received: from sainfoin-out.extra.cea.fr ([132.167.195.15]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 05 Dec 2010 17:02:38 +0100 Received: from pisaure.intra.cea.fr (pisaure.intra.cea.fr [132.166.88.21]) by sainfoin.extra.cea.fr (8.14.2/8.14.2/CEAnet-Internet-out-2.0) with ESMTP id oB5G2ctr011466 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sun, 5 Dec 2010 17:02:38 +0100 Received: from muguet2.intra.cea.fr (muguet2.intra.cea.fr [132.166.192.7]) by pisaure.intra.cea.fr (8.14.4/8.14.4) with ESMTP id oB5G2bCT017037 for ; Sun, 5 Dec 2010 17:02:38 +0100 (envelope-from Pascal.CUOQ@cea.fr) Received: from levau.intra.cea.fr (levau.intra.cea.fr [132.166.88.52]) by muguet2.intra.cea.fr (8.13.8/8.13.8/CEAnet-Intranet-out-1.1) with ESMTP id oB5G2b8c009545 for ; Sun, 5 Dec 2010 17:02:37 +0100 Received: from LAXA.intra.cea.fr ([132.166.64.47]) by levau.intra.cea.fr with Microsoft SMTPSVC(6.0.3790.4675); Sun, 5 Dec 2010 17:02:37 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: Modify macro and caml_initialize function Date: Sun, 5 Dec 2010 17:02:37 +0100 Message-ID: <5EFD4D7AC6265F4D9D3A849CEA92191902182AD6@LAXA.intra.cea.fr> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Modify macro and caml_initialize function Thread-Index: AcuTonAoqzXVyUIWT4i+2wL6HAoXXgA8AMiq References: <20101204110006.A6F91BC57@yquem.inria.fr> From: "CUOQ Pascal" To: , X-OriginalArrivalTime: 05 Dec 2010 16:02:37.0504 (UTC) FILETIME=[D6353400:01CB9495] X-Spam: no; 0.00; cuoq:01 cuoq:01 ocaml:01 val:01 val:01 byterun:01 idiom:01 wrote:01 maintainers:01 heap:01 heap:01 cea:01 computation:01 grep:01 caml:02 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 =3D 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"=20 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 =3D=3D 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