koka-lang / koka

Koka language compiler and interpreter
http://koka-lang.org
Other
3.16k stars 151 forks source link

Memory usage of repl increases after each reload #438

Open chtenb opened 5 months ago

chtenb commented 5 months ago

Reproduction Enter the Koka repl and load some program, like :l samples/all.kk. Run :r a few times. Notice the memory usage of the koka process increases with about 50MB each time. This can get out of hand quite a bit when programming with a repl open for the recompile+test cycle.

Workaround Exit and restart the repl.

TimWhiting commented 5 months ago

This is a known issue. It also happens with the language server / vscode extension. I'm pretty sure it has to do with Haskell's laziness. I'd love to figure this out, and I've done some work in trying to figure it out, but haven't ever completely solved the memory leak. Do you have any experience debugging Haskell memory leaks?

chtenb commented 5 months ago

No, unfortunately I have very little experience in using Haskell beyond small toy projects. But I have heard many times people complaining about these bugs being hard to track down. I once saw a talk where someone made a compelling point about the StrictData language extension being very helpful in avoiding accidental memory leaks. But that only works for your own types, the types from libraries (including prelude) keep their own laziness semantics.

daanx commented 5 months ago

Yes -- there is some kind of space leak... I think it is a laziness issue but haven't been able to find it (yet)... I think it has to do with the modules hanging on to some intermediate (maybe unevaluated) parts... but not sure. We need to bootstrap Koka in Koka some day :-D ... garbage free!