amuletml / amulet

An ML-like functional programming language
https://amulet.works/
BSD 3-Clause "New" or "Revised" License
324 stars 14 forks source link

High memory utilization on 1.0.0.0 (d6b1bcb1) #274

Open Lupus opened 4 years ago

Lupus commented 4 years ago

amc uses gigabytes of memory to compile ~1k sloc codebase. I didn't run into this issue with 0.7. My VM has 4 GB of ram. It does not seem to be connected with specific constructs, just commenting out portions of code make memory usage go down until it finally manages to compile within 4GB that I have.

Lupus commented 4 years ago

To compare, 0.7 uses less that 100MB of ram for the same codebase and runs much faster.

SquidDev commented 4 years ago

I can't think of any obvious changes in the compiler which would cause such a blowup - I will do some profiling later today.

The standard library definitely has some impact on this (assuming you're using it). Using the compiler from 662992a8, and running with time amc +RTS -s -RTS compile load-prelude.ml:

In both cases, GC amounts to ~40% of runtmie, which is a little worrying. Optimisation is something we really need to work on. That said, the maximum residency is never more than 15MB, so curious that it's not compiling on a 4GB machine.

SquidDev commented 4 years ago

@Lupus Would you be able to run amc compile with the --time flag (e.g. amc compile --time timings your_program.ml) and post the resulting file as a gist? Would be interesting to see what the slow down is. I realise this doesn't cover memory usage, but I suspect the two are related.

SquidDev commented 4 years ago

I fixed a rather embarrassing case of exponential blowup of the type-class trie when combining environments (see b4d4784f21501cefde598befc2e3531e6b26c4c7), which has dramatically improved performance in some cases (40s → 3.7s). It might be worth trying that version and seeing what, if any, improvements it makes. Doesn't really seem to change loading the prelude at all, but you might be lucky :).

Lupus commented 4 years ago

Cool, I'll give it a try when I get back to the project that uses amulet. Thanks!