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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id B15A97EE35 for ; Thu, 21 Apr 2016 18:03:32 +0200 (CEST) IronPort-PHdr: 9a23:ehVqmxc9lFFOV/oKWmehLsTQlGMj4u6mDksu8pMizoh2WeGdxc+6YB7h7PlgxGXEQZ/co6odzbGG4+a+CSdRvN6oizMrTt9lb1c9k8IYnggtUoauKHbQC7rUVRE8B9lIT1R//nu2YgB/Ecf6YEDO8DXptWZBUiv2OQc9HOnpAIma153xjLDivcODKFQVzBOGIppMbzyO5T3LsccXhYYwYo0Q8TDu5kVyRuJN2GlzLkiSlRuvru25/Zpk7jgC86l5r50IeezAcq85Vb1VCig9eyBwvZWz9Er1dhaU/nYXTkkRlxNJBUCFsEC7Dd/NtX7VrOdy3zOLdej/Sb0/WT3qu6huQRvlgycOHzE8+WDTzMd3ifQIjgimoklQyoTOYYyRfMF1fq7HcMlSEWVIVNxQWigHGYi8YpECFcIOOO9Zq8/2oF5Y/kj2PhWlGO66kmwAvXTxx6Bvlrl4HA== Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-ig0-f169.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.213.169; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.213.169 as permitted sender) identity=mailfrom; client-ip=209.85.213.169; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ig0-f169.google.com) identity=helo; client-ip=209.85.213.169; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-ig0-f169.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CaAAA4+RhXj6nVVdFeFoNANX0GpzmBUY9pdgENgXMkgjqDMAKBKwc4FAEBAQEBAQEBEQEBAQEHCwsJIS+CLYIVAQEEEhEEGQEbEgsBAwwGBQsDCgICCR0CAiEBAREBBQEKEgYTEgIOh3IBAxIOoR6BMT4xizaBaoJXhxUKGScDClGEHwEBAQEBAQQBAQEBAQEUAQUKBW2FJYRLgkEJgT+DNoJWBYYzDJEfMYFVhCaCdYMugXaCNIxch0+GIREegQ4eAQGCOR6BbyAwAYh1AQEB X-IPAS-Result: A0CaAAA4+RhXj6nVVdFeFoNANX0GpzmBUY9pdgENgXMkgjqDMAKBKwc4FAEBAQEBAQEBEQEBAQEHCwsJIS+CLYIVAQEEEhEEGQEbEgsBAwwGBQsDCgICCR0CAiEBAREBBQEKEgYTEgIOh3IBAxIOoR6BMT4xizaBaoJXhxUKGScDClGEHwEBAQEBAQQBAQEBAQEUAQUKBW2FJYRLgkEJgT+DNoJWBYYzDJEfMYFVhCaCdYMugXaCNIxch0+GIREegQ4eAQGCOR6BbyAwAYh1AQEB X-IronPort-AV: E=Sophos;i="5.24,513,1454972400"; d="scan'208";a="215316775" Received: from mail-ig0-f169.google.com ([209.85.213.169]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 21 Apr 2016 18:02:55 +0200 Received: by mail-ig0-f169.google.com with SMTP id m9so69817523ige.1 for ; Thu, 21 Apr 2016 09:02:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=JBLK84xGHEiKNGYxdscTSfeuZMC1/k8D+nBlWL+vGGY=; b=Fd6wOkXvu4+ibHSQr0Ryu0mZcn5Ipgqwmmr7DzVSKMnGEzaQn33HJMAFLHKp+XCv1p ZrvibiF6GVZXN7lpq0nkqiQnTlZkYvS6/jPwWP3cqaew9+uIMt4Sj85LGJ0BacBTQJB6 q81DUzucjoIeMRBtH5XxtWrXnEZGSdgABDK0Y0d6I14tJmiXhQTBa76akSa78bmGB7zG FKRXE/PVflEXYpy9JMa5UYWloTQQc9KIVjk2oy3pupqZA8GrKTGZxRLPD37shWabjLSC meHnEFdiSSE3Eo81OfVgjnqk+yP5N6n7wAp8JqQbHlvcYNVn9J2tB6SUks3ejtC4VNEG oCpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=JBLK84xGHEiKNGYxdscTSfeuZMC1/k8D+nBlWL+vGGY=; b=gq5mve6wJ+4gLzsofF0d02+JrzouXbtDs8ZrsyDZB4h4eHmbn6bVweCWzVITRg/h/W ZfEWi6R6bA/FPAmFM4IQoz2nfPyCH/jtantimP/etIqJk4frIYYCcOGXj2ClS8J0jgt3 qplBSFjpN2EIsoePSiyT/KMBYJCyK5wo8SqopuVP+uT7oeLa5H+lCXe7FLm6CegKmkH2 KhuLiQLbvOK+GsIR3BknlNZsBO44N+PCr2DY/PUPdF8SSSnRaEJJP318RQ+eRI4mqomz 0I091V0m6No8G3770mLx/ytBdgSyA99aCMiJYbKXB9/oa3W2sybOlifqp7NWwI+/Lo1L /F4Q== X-Gm-Message-State: AOPr4FXc2hoDsmjjwZjhU1KyCu/NU1WYzgv3xX7zHBUd88FlAWEpM1TsM8m3w4JFA/gGi/TwCtDr9V/Z5gD0bQ== X-Received: by 10.50.23.80 with SMTP id k16mr4924299igf.94.1461254574094; Thu, 21 Apr 2016 09:02:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.17.4 with HTTP; Thu, 21 Apr 2016 09:02:14 -0700 (PDT) In-Reply-To: References: From: Gabriel Scherer Date: Thu, 21 Apr 2016 12:02:14 -0400 Message-ID: To: Gregory Malecha Cc: Yaron Minsky , Jonas Jensen , caml users Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] Question about Optimization Another approach that might be worth trying (sorry for not thinking about it earlier) is MetaOCaml. I tend of think of it as a tool to explicitly specify and control partial evaluation strategies. Jeremy Yallop teaches MetaOCaml and some optimization tricks using it. See this excellent IOCaml notebook showing how to optimize a sequence of operations on a simple stack machine using MetaOCaml, which is not far from the discussed application. http://ocamllabs.github.io/iocamljs/staging2.html (I don't have an opinion on effectiveness of user-defined rewriting for OCaml code, I guess one should try to see how it goes. My take-away from the usage in the Haskell community is that it's very useful in some situations but also very fragile.) On Thu, Apr 21, 2016 at 11:45 AM, Gregory Malecha wrote: > Thanks for the feedback. It sounds like there are reasonable ways to do this > if you write your programs in such a way that everything can be done via > inlining. While I agree that this works in many cases, it doesn't seem > powerful enough to solve everything. For example, equations that are only > provable by induction are not optimizable by this strategy (without some > pretty fancy tricks). > > Do you believe that having a rewriting facility is unnecessary? > Undersireable (it makes the compiler too complex, too slow, too > unpredictable)? Or do you think that it would be useful, but no one has done > anything on it? > > Thanks. > > > On Thu, Apr 21, 2016, 4:45 AM Yaron Minsky wrote: >> >> Also, Core_kernel's Sequence type fills a similar purpose. And Flambda >> does a good job of optimizing the iteration in Sequence, from what I've >> overheard about our experiments. >> >> On Thu, Apr 21, 2016 at 5:32 AM, Jonas Jensen wrote: >>> >>> On 21 April 2016 at 09:13, Gregory Malecha wrote: >>> > >>> > I'm wondering if there is any work (and interest) on supporting >>> > user-defined optimizations similar to GHC's rewrite rules in the Ocaml >>> > compiler. For example, a standard example would be specifying map fusion: >>> > >>> > map f (map g ls) = map (fun x -> f (g x)) ls >>> >>> A "boring" and practical answer is that you get this optimization by >>> writing your long chain of map, filter, bind, etc. using Batteries' >>> Enum >>> (http://ocaml-batteries-team.github.io/batteries-included/hdoc2/BatEnum.html) >>> or the stand-alone Gen package >>> (http://cedeela.fr/~simon/software/gen/Gen.S.html). It looks >>> superficially like list map, but the order of execution will be like >>> after a fusion, which should improve cache locality and avoid >>> allocations of intermediate lists. >>> >>> Cheers, >>> Jonas >>> >>> >>> -- >>> Caml-list mailing list. Subscription management and archives: >>> https://sympa.inria.fr/sympa/arc/caml-list >>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >>> Bug reports: http://caml.inria.fr/bin/caml-bugs > > -- > > - gregory malecha > gmalecha.github.io