Compared to the other parts of the toolchain, launching utop via dune feels very slow. Is there any tricks to speed up the process?
What’s happening at the last step that causes such a slow down? It’s always where one very long delay occurs for me (> 10s). Even if my project is fully built.
Comparatively, I found I’m able to get access to a REPL almost instantly with the following commands:
# terminal 1, don't lock the dune file
rg --files | entr -rc dune build
# terminal 2, load a basic REPL with readline support.
# Reload with ctrl+d
while true;do dune top >.ocamlinit && rlwrap ocaml;sleep 0.1;done
I have not noticed the slow startup. In any case, my use case for “dune utop” is that it takes care of loading an entire project into utop. Doing this manually is quite tedious.
dune utop was available a few years before #use_output "dune ocaml top";;. It actually links all the code together in a binary, which can be slower than loading modules in the default repl, but is much faster when the codebase is large.
We are talking about linking of bytecode libraries, right? I’m not sure why this would be noticeably slower or faster than loading modules in the toplevel, which I assume uses Dynlink internally.
I don’t have actual numbers to provide, I thought it was an expected difference. But I could try to gather something.
By having a quick look I also found another difference, #use_output "dune ocaml top" in utop gets me an error. This is on ahrefs’ codebase, don’t have a small repro yet.
utop # #use_output "dune ocaml top";;
File "(command-output)", line 1:
Error: Reference to undefined global `Dune_site__Dune_site_data'
My understanding is that anyone would be welcome to work on replacing the current dune utop implementation by something better – with the risk of having to fix bugs along the way, or of finding out that it does not work for a good reasons we don’t know yet. Any volunteer? ( @benjamin-thomas ? )
I could try. I was unsuccessful in bootstrapping the project however (I get compilation errors), so I may need a bit of guidance to get started and become a bit of a burden.
Let me know if me giving it a try sounds interesting to you @rgrinberg
Thanks @gasche for the ping; I actually had missed this discussion and only learned about it from the Github issue filed by @grayswandyr. Perhaps @benjamin-thomas can try the curren (unreleased) version of Dune and report back here if it improves things (hopefully it will!).
The compilation speedup is very noticeable for me. Whereas before I would have to wait about 12-13s to access the REPL on a simple project but an oldish computer, now I can access it in 3-4s.