From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] large parametrized polymorphic variant type combinations take forever to compile
Date: Wed, 11 Jul 2007 02:19:35 +0100 [thread overview]
Message-ID: <200707110219.35727.jon@ffconsultancy.com> (raw)
In-Reply-To: <20070711.091002.39162301.garrigue@math.nagoya-u.ac.jp>
On Wednesday 11 July 2007 01:10:02 Jacques Garrigue wrote:
> Seems you're lucky. The fix I did yesterday after reading your first
> mail, combined with the fixes following the previous discussion,
> solved the problem. Compilation times are now about 7s using less than
> 7MB, for all of the 3 files, using ocamlc (bytecode). Of course, you
> can still expect quadratic behaviour if your types grow more...
Isn't it a really bad idea to autogenerate polymorphic variant type
constructors anyway because, sooner or later, you'll get a hash clash? In
fact, wouldn't that be platform specific?
I would recommend factoring the sum type by the argument types of the
contructors in this case. Looking at Sam's files, this is trivial. Just
replace this:
type ('a,'b) t1 = [
| `t1_a of 'a option
| `t1_b of 'b list
| `t1_a0 of 'a option
...
| `t1_a9 of 'a option
| `t1_a10 of 'a option
...
| `t1_a1000 of 'a option
with this:
type t1 = [
| `t1_int of [
| `a
| `a0
| `a10000 ] * int
| `t1_float of [`b] * float
]
and this:
let f ~fa ~fb = function
| `t1_a a -> fa a
| `t1_b b -> fb b
| `t1_a0 a -> fa a
...
| `t1_a1000 a -> fa a
with this:
let f ~fa ~fb = function
| `t1_int(_, a) -> fa a
| `t1_float(_, b) -> fb b
The following code autogenerates an equivalent to small1.ml and it compiles
100x faster:
open Printf
let () =
printf "type t1 = [\n";
printf "| `t1_int of [\n| `a\n";
for i=0 to 1000 do
printf " | `a%d\n" i
done;
printf "] * int\n";
printf "| `t1_float of [`b] * float\n";
printf "]\n";
printf "let f ~fa ~fb = function\n";
printf "| `t1_int(_, a) -> fa a\n";
printf "| `t1_float(_, b) -> fb b\n";
Doing the same for small2.ml and small.ml, the final compilation time is
0.09s.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The OCaml Journal
http://www.ffconsultancy.com/products/ocaml_journal/?e
next prev parent reply other threads:[~2007-07-11 1:25 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-06 16:30 compiling large file hogs RAM and takes a long time Sam Steingold
2007-06-06 16:51 ` [Caml-list] " skaller
2007-06-06 17:05 ` Sam Steingold
2007-06-07 15:52 ` Sam Steingold
2007-06-08 1:02 ` [Caml-list] " Jacques Garrigue
2007-06-08 1:51 ` skaller
2007-06-08 2:26 ` Yaron Minsky
2007-06-08 9:05 ` Thomas Fischbacher
2007-06-08 9:35 ` skaller
2007-06-08 9:55 ` Thomas Fischbacher
2007-06-08 13:39 ` Sam Steingold
2007-06-08 12:30 ` [Caml-list] " Jacques Garrigue
2007-06-15 15:41 ` Sam Steingold
2007-06-15 18:56 ` [Caml-list] " Jon Harrop
2007-06-15 20:06 ` Sam Steingold
2007-07-09 20:22 ` large parametrized polymorphic variant type combinations take forever to compile Sam Steingold
2007-07-09 22:45 ` Sam Steingold
2007-07-09 23:37 ` [Caml-list] " Jacques Garrigue
2007-07-10 7:09 ` Christophe Raffalli
2007-07-10 7:31 ` Jacques Garrigue
2007-07-10 14:16 ` Sam Steingold
2007-07-10 16:49 ` Sam Steingold
[not found] ` <46938BDA.1090605@podval.org>
2007-07-11 0:10 ` [Caml-list] " Jacques Garrigue
2007-07-11 1:19 ` Jon Harrop [this message]
2007-07-11 2:23 ` Jacques GARRIGUE
2007-07-11 13:12 ` Sam Steingold
2007-07-11 19:17 ` [Caml-list] " Jon Harrop
2007-07-10 3:34 ` [Caml-list] " skaller
2007-07-10 13:27 ` Sam Steingold
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200707110219.35727.jon@ffconsultancy.com \
--to=jon@ffconsultancy.com \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).