From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id E7E64BC69 for ; Tue, 15 Jan 2008 06:06:15 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq4HAH7Oi0fUnw7VhWdsb2JhbACCNI1SAQEBCAQGDxMHmRY X-IronPort-AV: E=Sophos;i="4.24,285,1196636400"; d="scan'208";a="7802602" Received: from ptb-relay02.plus.net ([212.159.14.213]) by mail3-smtp-sop.national.inria.fr with ESMTP; 15 Jan 2008 06:06:15 +0100 Received: from [80.229.56.224] (helo=beast.local) by ptb-relay02.plus.net with esmtp (Exim) id 1JEe06-00072X-M1 for caml-list@yquem.inria.fr; Tue, 15 Jan 2008 05:06:14 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Re: Hash clash in polymorphic variants Date: Tue, 15 Jan 2008 04:59:03 +0000 User-Agent: KMail/1.9.7 References: <200801140720.02094.ober.14@osu.edu> <200801140956.25449.ober.14@osu.edu> <20080115.123621.184910428.garrigue@math.nagoya-u.ac.jp> In-Reply-To: <20080115.123621.184910428.garrigue@math.nagoya-u.ac.jp> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200801150459.03896.jon@ffconsultancy.com> X-Spam: no; 0.00; hash:01 variants:01 marshalling:01 variants:01 hash:01 logarithmic:01 caching:01 run-time:01 lablgl:01 frog:98 polymorphic:01 polymorphic:01 wrote:01 compile:01 caml-list:01 On Tuesday 15 January 2008 03:36:21 Jacques Garrigue wrote: > Unfortunately, this would make marshalling between different programs > much more complicated... Do people marshal polymorphic variants between different programs? > Another advantage of knowing the hash function at compile time is > that you can generate efficient code for pattern matching. Since you > already know the ordering of tags, it is easy to generate a decision > tree. I didn't check very recently about efficiency for polymorphic > variants, but the depth of the decision tree is logarithmic in the > number of tags involved in the pattern matching, and if you can keep > it below 3 or 4 (about 10 tags) you can be actually faster than a > jump table. For 3-16 tags on AMD64, jump tables (ordinary variants) are 2x slower than decision trees (polymorphic variants) when branches are taken at random. However, jump tables are consistently up to 2x faster when a single branch is taken repeatedly. So caching jump tables is more effective at run-time optimizing pattern matches over ordinary variants than branch prediction is at optimizing decision trees for pattern matches over polymorphic variants. So the advantage of a decision tree is probably insignificant on real code because it will lie between these two extremes. > Now concerning the risks of name conflicts. The main point of > polymorphic variants is that there is only a conflict if the two tags > appear in the same type. And logically the type should stay small. > If you want to put all GLenum's inside the same type, then you may > well end up with conflicts. But what LablGL shows is that in practice > only a small number of tags are used together. Can LablGL's design support OpenGL extensions? -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e