Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
compiling large file hogs RAM and takes a long time.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-07-11 (00:10)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] large parametrized polymorphic variant type combinations take forever to compile
From: Sam Steingold <>

> actually these horrors are observed with 3.09.3.
> we are planning to upgrade to 3.10 soon.

Note that it should be the 3.10 CVS version, not 3.10.0.
Or you can wait for 3.10.1 (but I have no idea when it will be.)

> > This could be improved, at least at the type-check
> > level, but again polymorphic variants were not implemented with
> > thousands of constructors in mind.
> too bad. any chance this could be fixed?

That the original implementation hadn't huge types in mind?
Too late: it would require a very different approach.
Also, as Christophe Raffalli pointed out, there are some features of
pattern-matching that are NP-complete by design.
But we can try to remove flagrant innefficiencies when we understand

> > Could you send me your real code, so that I can see whether something
> > unexpected is happening?
> attached

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...

By the way, you're also lucky for the generated code: due to the
naming of your constructors, the code for is very compact
and efficient. Of course, this is not going to be true in general.
(You can see the result of pattern-matching compilation with
'ocamlc -c -dlambda')

Jacques Garrigue