benlubas / molten-nvim

A neovim plugin for interactively running code with the jupyter kernel. Fork of magma-nvim with improvements in image rendering, performance, and more
GNU General Public License v3.0
532 stars 30 forks source link

[Bug] Extremely slow once kernel is active #27

Open Thesola10 opened 10 months ago

Thesola10 commented 10 months ago

Description

Precisely the same issue as upstream dccsillag/magma-nvim#100

benlubas commented 10 months ago

@Thesola10 if I had to guess this is the same issue that I described here. I'm not 100% on that.

If you could provide more information about how you're installing python deps and the jupyter kernel kernel, that could help out. In the meantime I can take a look at the section of code pointed out in that issue.

Another thing that you could do is run the :MoltenInfo command (might need to update the plugin first) and compare working to non-working kernels. I'm not quite sure how that could help solve things, but might suggest that it's infact similar to the issue I had

Thesola10 commented 10 months ago

Indeed my Neovim setup is provided through Nix, while my Jupyter kernels are installed system-wide from Arch repos. Is there a way this situation could be detected and an error message shown?

I'll try and upgrade my Nix Neovim's Python to 3.11 to match my system-wide Arch Python

benlubas commented 10 months ago

My broken kernel is failing to be ready over and over again. I'm still not sure why it's causing the editor to lag out. Molten only checks if it's ready twice a second, and doesn't wait on the kernel to be ready.

I think this could definitely use a "max_tries" or something so that it will at least eventually error out. But the editor would still be lagging while we wait, normal kernels can take a decent amount of time to start up (although they don't lag the editor).

benlubas commented 10 months ago

Do you have any working kernels currently?

Thesola10 commented 10 months ago

Kernels that don't use Python as a host executable work.

Thesola10 commented 10 months ago

Correction: only non-Python kernel hosts work. Nix breaks a lot of Python's functionality, and I suppose it doesn't look into the default PYTHONPATH.

benlubas commented 10 months ago

Okay, I can at least help you get a python kernel running b/c I'm using nix, and it's working for me. Probably the easiest way to do this would be, to use the flake.nix file in this repo. Get into the dev shell that creates. You should then have python and ipython from the shell, and you can run python -m ipykernel install --user --name <kernel_name>. For me, this installs a kernel that works with molten anywhere (even outside of the dev shell).

One important thing to note:

I'm really new to nix, so I'm not the best for explaining why this works.

benlubas commented 10 months ago

while my Jupyter kernels are installed system-wide from Arch repos

Does this mean that you installed them with the arch package manager instead of with the python command mentioned above? That could be the problem, although I'm not sure why it doesn't work

Thesola10 commented 10 months ago

You can check out my current Neovim config over here, but in the mean time, I appreciate the help

I think I can just add an option to load Arch's Python as the default runtime even through the Nix package.

benlubas commented 10 months ago

One more thing to check out if that doesn't work: https://github.com/dccsillag/magma-nvim/pull/69

You can spawn the kernel in a separate terminal, and attach to it the way that's mentioned in the PR (I haven't tried this, but it should still work). I really should document that, I didn't realize that it was a thing until I stumbled across it last night while looking through magma issues that I'd like to fix/implement in molten.

Definitely leave an update if/when you find a solution. I'm planning to write a nix(os) wiki page b/c there is certainly some jank there.

Bekaboo commented 10 months ago

I am experiencing this bug too. This is a serious bug, it make the whole nvim session freeze, adds an increasing latency that grows from about 1s to 10s before each keystroke, it even freeze my desktop (KDE Plasma) once, seems that there is an infinite loop somewhere.

Here is my :MoltenInfo, hope it helps.

image

benlubas commented 10 months ago

This seems to happen when the kernel is installed in a certain way. Not sure what way that is, but installing into a virtual environment the way the docs suggest seem to work reliably. If you want a quick fix you could try to just follow those. I would still like to figure this issue out though.

If you could include as many details as possible about your setup that might help. Information like, OS, how you installed python, the version of python, version of ipykernel, how you installed the jupyter kernel, does the kernel work in jupyter lab (I suspect that it will, I have a kernel that causes this issue and it works fine in jupyter lab for me). and any other details you might think are relevant.

It seems like this wasn't installed in a virtual environment, which could also be related? I'm not sure. I've been unable to recreate this issue reliably on a normal (non-nixos) machine, so a minimal repro would be really helpful if you could create one!

@Bekaboo

Bekaboo commented 10 months ago

Unfortunately, I can no longer reproduce the bug using a globally installed jupyter kernel. I will report here once I encounter this bug again or have found a reliable way to reproduce it on my end.

ddkasa commented 6 months ago

If this is still an issue I was getting the problem when running a global Jupyter config. I recently reinstalled my iPython into a Pipx virtual environment which broke the global Jupyter installation.

After reinstalling iPython back into the global config the slow down completely disappeared for me. So I am guessing the kernel could never launch in the background due to a missing dependency and kept continuously hanging the Neovim instance.

benlubas commented 6 months ago

@ddkasa could you leave the command that you used to install it globally? That could be a/the problem.. but I think that there's some way for us to handle it b/c I had a kernel that hung neovim but would work in jupyter lab.

ddkasa commented 6 months ago

@benlubas It's the standard $ pip install jupyter command. After that I ran $ pip uninstall ipython.

I just tested this again and it was hanging again, but Jupyter notebook/lab would work as it was sourcing another kernel from another environment.

After re running $ pip install jupyter it reinstalls Ipython and that fixes the slowdown again.

I am using Pyenv to manage my Python though, so that might make it different, but that should act the same as normal installation in theory.

Molten Info: image

I have my nvim python set through vim.g.python3_host_prog = "~/.pyenv/versions/3.12.0/bin/python3.12".

mbpowers commented 4 days ago

I had the same lag after MoltenInit while using a venv for python3_host_prog and cheakhealth looked good. I had jupyter installed on the system but not in the venv so pip install jupyter in the venv did the trick.