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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id BC2C7BC57 for ; Sun, 7 Mar 2010 01:48:55 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvgBAJuGkkvZSMDdimdsb2JhbACbSRUBAQEKCQwHEQUftnqEeAQ X-IronPort-AV: E=Sophos;i="4.49,596,1262559600"; d="scan'208";a="54153331" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail1-smtp-roc.national.inria.fr with ESMTP; 07 Mar 2010 01:48:55 +0100 Received: from smtp05.web.de (fmsmtp05.dlan.cinetic.de [172.20.4.166]) by fmmailgate01.web.de (Postfix) with ESMTP id E693114B8043C; Sun, 7 Mar 2010 01:48:54 +0100 (CET) Received: from [85.216.85.71] (helo=frosties.localdomain) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #314) id 1No4fu-0000oj-00; Sun, 07 Mar 2010 01:48:54 +0100 Received: from mrvn by frosties.localdomain with local (Exim 4.71) (envelope-from ) id 1No4fr-0004Dj-Ua; Sun, 07 Mar 2010 01:48:52 +0100 From: Goswin von Brederlow To: ygrek Cc: caml-list@inria.fr Subject: Re: [Caml-list] no_scan_tag and int array References: <20100306112645.a74bb0c4.ygrekheretix@gmail.com> Date: Sun, 07 Mar 2010 01:48:51 +0100 In-Reply-To: <20100306112645.a74bb0c4.ygrekheretix@gmail.com> (ygrek's message of "Sat, 6 Mar 2010 11:26:45 +0200") Message-ID: <87eijxot1o.fsf@frosties.localdomain> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX1/XK6oEzSVUoNd9mv0veLrdBIc7Ta88fH/YPV/u VNNOQCl0xceqiCYJUEB7857ZB9wA8uo91CO5leAvDebCuLMiIJ /tgLwOw3c= X-Spam: no; 0.00; printf:01 gettimeofday:01 printf:01 gettimeofday:01 integers:01 arrays:01 compiler:01 compiler:01 arrays:01 pointer:01 pointer:01 segfaults:01 ,...:98 mfg:98 polymorphic:01 ygrek writes: > Hello, > > Consider this code: > > open Printf > > let measure f = > let t = Unix.gettimeofday () in > let () = f () in > printf "%.4f sec" (Unix.gettimeofday () -. t) > > let () = > let gc () = for i = 1 to 10 do Gc.full_major () done in > let a = Array.make 4_000_000 0 in > measure gc; > printf " normal %u (%u)\n%!" (Array.length a) (Gc.stat ()).Gc.live_words; > > Obj.set_tag (Obj.repr a) (Obj.no_scan_tag); > measure gc; > printf " no_scan_tag %u (%u)\n%!" (Array.length a) (Gc.stat ()).Gc.live_words; > > measure gc; > printf " no array (%u)\n%!" (Gc.stat ()).Gc.live_words; > () > > Output looks like : > > 0.2281 sec normal 4000000 (4000165) > 0.0002 sec no_scan_tag 4000000 (4000165) > 0.0002 sec no array (164) > > So, as expected, setting No_scan_tag on the array of integers prevents GC from uselessly > scanning the huge chunk of memory. Looks like polymorphic array functions still work fine and What polymorphic array function? I don't think Array.length is a good test as it looks at the header of the array to see how many words the array has. > GC correctly reclaims array memory when it is not referenced anymore. > Apparantly this trick is not allowed for float array as they have a special tag set. But does the GC scan float arrays? > The question is - how safe is this? And even more, could the compiler itself set this tag? >>From the GC side this should be perfectly save. But all the array functions should be checked and not just Array.length before doing this. And yes, the compiler could mark arrays with primitive types (int, char, unit,...) and even type x = A | B | C for not scanning. This also applies to records, tuples and (polymorphic) variant types that contain no pointer. It would break though if someone declares an int array and then stores a pointer in there. But if you do something illegal then you get to keep the segfaults. MfG Goswin