From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id B44787EC41 for ; Thu, 25 Oct 2012 09:37:04 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of dhouse@janestreet.com) identity=pra; client-ip=38.105.200.115; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="dhouse@janestreet.com"; x-sender="dhouse@janestreet.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of dhouse@janestreet.com designates 38.105.200.115 as permitted sender) identity=mailfrom; client-ip=38.105.200.115; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="dhouse@janestreet.com"; x-sender="dhouse@janestreet.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@nyc-dmz-mxout2.janestreet.com) identity=helo; client-ip=38.105.200.115; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="dhouse@janestreet.com"; x-sender="postmaster@nyc-dmz-mxout2.janestreet.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtMAAEPriFAmachzl2dsb2JhbABEwhYrAQEBAQEIFgc7gh4BAQEEEgITGQEBNwEPCwsNLiISAQUBHAYTCBqHYgMBnhNgCQOKa4QzAQWPFAaLYYZtlXaOWBYphBKCGA X-IronPort-AV: E=Sophos;i="4.80,646,1344204000"; d="scan'208";a="178843334" Received: from mx2.janestreet.com (HELO nyc-dmz-mxout2.janestreet.com) ([38.105.200.115]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 25 Oct 2012 09:37:03 +0200 Received: from nyc-qsv-mail1.delacy.com ([172.25.22.57]) by nyc-dmz-mxout2.janestreet.com with esmtp (Exim 4.76) (envelope-from ) id 1TRHzx-0006EZ-Iv for caml-list@inria.fr; Thu, 25 Oct 2012 03:37:01 -0400 Received: from nyc-dmz-mxgoog1.delacy.com ([172.25.224.109] helo=mxgoog1.janestreet.com) by nyc-qsv-mail1.delacy.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1TRHzx-0001k9-HU for caml-list@inria.fr; Thu, 25 Oct 2012 03:37:01 -0400 Received: from mail-wi0-f198.google.com ([209.85.212.198]) by mxgoog1.janestreet.com with esmtp (Exim 4.76) (envelope-from ) id 1TRHzx-0005bu-DU for caml-list@inria.fr; Thu, 25 Oct 2012 03:37:01 -0400 Received: by mail-wi0-f198.google.com with SMTP id cb5so1317142wib.9 for ; Thu, 25 Oct 2012 00:37:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=wGiu35pBNCVVr4OEfsTuikpToSP/b6CAFEjicrRh2BM=; b=vwYGohxgA0iY5C/vsjKuLS9ba99VGiELg3AHm2265Eh7VvqBkrVKOOCkAblvCJg8pC XlBRbapcN6aAiPUxHxbILcfq/ofMSelKnsHEhb92yg/fPuy+wVmVA0T1DvJ1ylLI5u0W 3MO79fo7sVNwrlx+cilgclAnuXBZGKfxoAHGI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=wGiu35pBNCVVr4OEfsTuikpToSP/b6CAFEjicrRh2BM=; b=c+gWps896K3u1oIWTPiitsj3fi4lynkqN6RO8W6gygDUnMlcA4Ej6nYuaUeDmfukmC a7gROXE8ef1FOK5IYtLuG6d+n2AHLPOwAkiSDBr8LDhNdgCfPF3UULnAMu/5uQQtTfkv zLkpsm6Skar0+f5eh8kmlbyBwbjJ0QFps6cc6zrPVXCTo2FsFDEO7lAht+xaC57JfD22 SK4UwcEFN0+mcfW2ROs8XyGWZWmP1ZimX4x1F8vr1JbrGI/zZyQ2W73punlp6fbGhZFB YnfnaVXKZiYjBYy5DjjC61aggRfTlUkVd1fpn4fLlL+5qUivYLpkvXygYz6Y3krDttHo /2/Q== Received: by 10.216.134.100 with SMTP id r78mr10159353wei.152.1351150620901; Thu, 25 Oct 2012 00:37:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.134.100 with SMTP id r78mr10159348wei.152.1351150620826; Thu, 25 Oct 2012 00:37:00 -0700 (PDT) Received: by 10.180.106.228 with HTTP; Thu, 25 Oct 2012 00:37:00 -0700 (PDT) X-Originating-IP: [80.169.196.210] In-Reply-To: References: <1351094817.12207.11@samsung> Date: Thu, 25 Oct 2012 08:37:00 +0100 Message-ID: From: David House To: David MENTRE Cc: Gerd Stolpmann , Oliver Bandel , caml users Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQnn8OfgTK3n/Bu/8Xw6MiODBPgsFKln3YmwFdKw2j9zIHJL+gHNTaUIsqQI9Uo/3YezLrym/EpKy8Ewsu0jA0rLhrp0DCXSd1SeOjBS9ZBD3JZJE5CcFTFTZJWKx/0gowc7aiDTbIgWAMCAN2IXiwHa15jBHg== Subject: Re: [Caml-list] Behaviour of an OCaml program: any possible GC improvement? On Thu, Oct 25, 2012 at 7:48 AM, David MENTRE wrote: >> Some improvement is also >> possible with simple tricks, e.g. if you have something like >> >> Number 0 >> >> where Number is from an algebraic type, and you use this term frequently, >> consider to add a constant for it, >> >> let n0 = Number 0 >> >> so this isn't reallocated all the time > > Thanks for the trick. As Martin pointed out, this isn't necessary for Number 0. Constant expressions are statically allocated. If you have two functions returning Number 0, you'll get two of them, but they'll still be statically allocated (so calling that function does not allocate for Number). This is actually even true of string literals, which are mutable: # let f () = "foo";; val f : unit -> string = # let x = f ();; val x : string = "foo" # let y = f ();; val y : string = "foo" # x.[0] <- 'g';; - : unit = () # y;; - : string = "goo" But other, similar tricks are worthwhile. For example, in async, it is very common to write "return ()" for the deferred that is immediately determined with value (). But doing so does a function call and allocates a deferred. So we have [Deferred.unit] for this common case.