Jupyter notebooks slowness/usability

I hope this doesn’t come across as a “complaining” post. I just have some big concerns about this and was curious if the problem is being addressed.

I am a primary contributor to a DOE funded project for a new, modern, differentiable code for accelerator physics simulations. I have been coding in Julia for about 2 years now, and thanks to many of you on this forum , Slack, etc feel I have a pretty good grasp of the language at this point. My development process consists of the REPL+ Revise.jl combo with VS code. This has overall been a breeze and pleasure to do development with.

Recently some colleagues at one of the labs asked me to perform some calculations, and I figured a Jupyter notebook would be perfect to show the computation step by step. However, I found Julia to be significantly slower in the notebook than in the REPL. The speed difference seems primarily associated with the JIT time. For example, one step of the computation required a numerical solution (I use NLSolve). In the REPL, the JIT time included it might be ~10 seconds. In Jupyter notebooks, the calculation was over 2 minutes. And any changes to the function to optimize would require another compilation, waiting another 2 minutes. This becomes basically unusable.

Last week I also taught a Julia crash course to some colleagues, and they expressed similar complaints about Jupyter notebooks, instead using the REPL.

Because I expect most users of our simulation code will use Jupyter notebooks for its ease of use and familiarity from Python experience, I am quite concerned to see how slow it is. I was wondering if this problem is being addressed and if others have a similar experience.

I’ve never seen this; the notebook is just running julia under the hood, so in principle it should be the same, as long as you are using the same Julia version.

How are you running the Jupyter notebook? Are you using vsCode with the IJulia kernel (i.e. the “Jupyter Kernel” selection in the “choose kernel” menu)? Or JupyterLab?

(I don’t think the REPL does any magic with the JIT, unless something new has been introduced here in recent Julia versions?)

I’ve also never seen this, and I use IJulia pretty much every day.

Two things I’ve noticed are

  • I believe IJulia is not precompiling in parallel on using, although I’m not sure that’s true - I made an issue that didn’t get any feedback
  • IJulia generally has more precompilation than the REPL, including repeated precompilation - I think this is because IJulia itself has to be active in your REPL session, so often transitive dependencies will already be loaded when you precompile an environment, and an env that was precompiled already has to precompile again if loaded in an IJulia context. I’ve seen the recommendation to add IJulia itself to the project environment to alleviate this which seems to help, but I still feel like I get more precompilation in IJulia than I’d expect