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 ACB4CBC57 for ; Sat, 6 Mar 2010 10:26:48 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnQBAO6ukUvRVdrakGdsb2JhbACRKoIQiAkIFQEBAQEJCQwHEwMfpV+BYYRrLYhJAQEDBQiEawQ X-IronPort-AV: E=Sophos;i="4.49,593,1262559600"; d="scan'208";a="54133478" Received: from mail-bw0-f218.google.com ([209.85.218.218]) by mail1-smtp-roc.national.inria.fr with ESMTP; 06 Mar 2010 10:26:48 +0100 Received: by bwz10 with SMTP id 10so96244bwz.22 for ; Sat, 06 Mar 2010 01:26:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :message-id:x-mailer:mime-version:content-type :content-transfer-encoding; bh=/HrwJEaSnUSHnfCDJtnp4dvO4qpZVnzJOcGQjqKZpNo=; b=BkEjijvtYGh+xhvXX1nYn/M3ITdkfJlDbsYQKksaqRzv86aTTF3yroS92MvoD9Ew5S jaQ0uGhsrGWEqTxVI3187QW1OnwXBr+5Lv6FKia3Dw8PMj1VzP/vtjwvrlnYvv8laY3Y rLN6X26ZpuoLbwZsZK9pLZbnXY9H5IOGphJdw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:x-mailer:mime-version:content-type :content-transfer-encoding; b=TsM3VWd7BKM9TzNSkZVDYWOAjpqDhS1nQffWiSY//MS8pqkkZN4rrdR2k0kBQ3jN7l 9vbL7Sup/cHDbilvxtklpfuBLzlS7eKdHKDOdL3fdansryE6HmjhFEaAprDQ/8IiJ8on p075FwxKibgnNuDmIhUu+1648gN0nJNjaT+70= Received: by 10.204.32.196 with SMTP id e4mr1382091bkd.131.1267867608147; Sat, 06 Mar 2010 01:26:48 -0800 (PST) Received: from lemon (177-89-133-95.pool.ukrtel.net [95.133.89.177]) by mx.google.com with ESMTPS id 13sm40423bwz.7.2010.03.06.01.26.47 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 06 Mar 2010 01:26:47 -0800 (PST) Date: Sat, 6 Mar 2010 11:26:45 +0200 From: ygrek To: caml-list@inria.fr Subject: no_scan_tag and int array Message-Id: <20100306112645.a74bb0c4.ygrekheretix@gmail.com> X-Mailer: Sylpheed 2.5.0 (GTK+ 2.12.12; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; printf:01 gettimeofday:01 printf:01 gettimeofday:01 integers:01 compiler:01 polymorphic:01 unix:01 unix:01 functions:01 int:01 referenced:02 chunk:02 output:02 float:03 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 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. The question is - how safe is this? And even more, could the compiler itself set this tag? -- ygrek http://ygrek.org.ua