-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Description
Hey, I investigated this issue because since upgrading to JupyterLab 4.3.0 and adding jupyter-collaboration, a lot of our users have been complaining about killing their servers on JupyterHub. What I found is that notebooks with text outputs get exponentially slower to open. I have a pretty small ~400 KB notebook that I let run for 43 minutes before it loaded as an example.
I ended up on this line of code being extremely slow in jupyter_server_ydoc: https://github.com/jupyterlab/jupyter-collaboration/blob/ed544ba982f55d1fd4a28d5124fbddc3043bbf89/projects/jupyter-server-ydoc/jupyter_server_ydoc/rooms.py#L163
If you dig deeper you will find that it's self._ycells.extend() from jupyter_ydoc that is really slow:
jupyter_ydoc/jupyter_ydoc/ynotebook.py
Line 248 in 5de54c8
self._ycells.extend([self.create_ycell(cell) for cell in cells]) |
Indeed, this here is really slow when you pass it massive lists of characters that we now see for text outputs: https://github.com/jupyter-server/pycrdt/blob/f7fb3aebb76c55aff3c82f5008fd135b87de488f/python/pycrdt/_array.py#L100
An easy workaround is commenting out this optimization in create_ycell():
jupyter_ydoc/jupyter_ydoc/ynotebook.py
Lines 168 to 169 in 5de54c8
if output.get("output_type") == "stream": | |
output["text"] = Array(output.get("text", [])) |
My problematic notebooks now load in a reasonable amount of time but this is just an untested workaround. I'm sure there is a good solution for the problem.
Reproduce
- Create a notebook with massive text output(s).
- Restart JupyterLab.
- Open the notebook.
- JupyterLab will be frozen.
Expected behavior
For notebooks to load in a reasonable amount of time even with big text outputs.
Context
@davidbrochart I think this issue might be the most relevant to you as you worked on the new stream outputs.