Ocamlopt + flambda requires a lot of memory to compile large array literal expressions #7244
Original bug ID: 7244
ocamlopt + flambda needs several GB of memory to build a file with a lot of (very) large array literals. ocaml 4.02.3 uses between 4 and 5 times less memory on the same files.
The attached file is generated by ragel, a parser generator which uses arrays to store the automata.
Steps to reproduce
build attached file with ocamlopt.opt -Oclassic ragel_file.ml. On my machine it requires 3.3GB of memory at peak to complete and several minutes. (-Oclassic or -O2 or anything else doesn't actually matter, there is no function in the test file)
(note the attached file is not the full ragel output but is enough to reproduce)
Comment author: joris
The file to reproduce is too large and i fail to upload it to mantis, so i've put it here : https://gist.github.com/jorisgio/8e8687be610d1c80a01c696a1aa68f98
Comment author: @Chris00
Not sure it is exactly the same but ocamlopt 4.03.0+flambda fails to compile the file https://github.com/Chris00/color_brewery/blob/master/src/color_brewery_palettes.ml with
Fatal error: exception Stack overflow
(without flambda, the file compiles fine).
Comment author: @chambart
After looking a bit more at that, the problem seems to come directly from the file size. There is no specific inefficiency, but the conversion to a sequence of lets makes it too big. One way to handle that may be to circumvent the let conversion by directly producing the let_symbol during closure conversion. It is quite sad to have to special case this, but I can't find any better solution.