liquidz / vim-iced

Clojure Interactive Development Environment for Vim8/Neovim
https://liquidz.github.io/vim-iced/
MIT License
524 stars 35 forks source link

First require locks up neovim for ~10 seconds #82

Closed devth closed 4 years ago

devth commented 5 years ago

After :IcedConnect the first :IcedRequire locks up neovim for about 10 seconds. During this time I can't move the cursor or do anything inside neovim. After that subsequent :IcedRequires run nearly instantly.

NVIM v0.3.2-996-g55c518588
Terminal: kitty 0.13.1

Ref https://github.com/liquidz/vim-iced/issues/77

liquidz commented 5 years ago

@devth Thank you for the reporting!

Does this problem occur in any project? Could you provide the steps to reproduce?

devth commented 5 years ago

I tried it in my yetibot project. It seems to repro on any file I try requiring after initial :IcedRequire.

Trying on a fresh project doesn't seem to freeze:

lein new iced-repro
cd iced-repro
iced repl

In neovim:

nvim src/iced_repro/core.clj
:IcedConnect
# nvim freezes for about 1 second 
<Leader>eb
# no freeze

So it doesn't appear to happen on a fresh project. I'll keep playing with it. Maybe has to do with how much source code is in the project?

devth commented 5 years ago

Noticed a large error after connecting and trying to :IcedEval a simple expression:

|| Connected.
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
|| Traceback (most recent call last):
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
||   File "<string>", line 3, in <module>
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
||   File "/Users/thartman/Library/Python/3.7/lib/python/site-packages/pynvim/api/nvim.py", line 287, in command
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
||     return self.request('nvim_command', string, **kwargs)
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
||   File "/Users/thartman/Library/Python/3.7/lib/python/site-packages/pynvim/api/nvim.py", line 182, in request
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
||     res = self._session.request(name, *args, **kwargs)
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
||   File "/Users/thartman/Library/Python/3.7/lib/python/site-packages/pynvim/msgpack_rpc/session.py", line 102, in request
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
||     raise self.error_wrapper(err)
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
|| Error detected while processing function
|| <lambda>7[1]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/nrepl.vim|130| <SNR>197_dispatcher[5]
/Users/thartman/.config/nvim/plugged/vim-iced/autoload/iced/di/bencode/python.vim|13| <SNR>219_decode_via_python[6]
|| provider#python3#Call[18]
|| pynvim.api.nvim.NvimError: b'Keyboard interrupt'

After that when I try to :IcedEval anything it just says Still reading....

liquidz commented 5 years ago

@devth I couldn't reproduce the problem with following steps...

I uses nvim 0.3.2. https://github.com/neovim/neovim/releases/tag/v0.3.2

$ nvim --version
NVIM v0.3.2
Build type: RelWithDebInfo
LuaJIT 2.0.5
...

It seems to me you use nvim 0.3.2(nightly), so could you update nvim 0.3.2(released) or later and test again?

devth commented 5 years ago

Upgraded to NVIM v0.4.0-1183-g8510d5ff8. Also upgraded to latest commit on vim-iced dev branch.

  1. Opened new neovim instance
  2. Ran iced repl in a terminal inside vim
  3. Opened slack.clj
  4. :IcedConnect
  5. <Leader>eb - immediately says Required in the statusline but then locks up for 10 seconds
liquidz commented 5 years ago

@devth Thanks! But I cannot reproduce yet.. I'll keep testing with yetibot.core

devth commented 5 years ago

Strange. I will also keep testing on my side and see if I can narrow down what's going on!

liquidz commented 5 years ago

@devth

  1. eb - immediately says Required in the statusline but then locks up for 10 seconds

The fact that "Required" is output means IcedRequire should have finished. So something else should be running afterwards. (It may be other configurations or other plugins)

I made a minimal configuration for vim-iced for breaking down this problem. https://scrapbox.io/vim-iced/Minimal_configuration Could you launch nvim with this minimal configuration and test again?

devth commented 5 years ago

Sorry for the delay. I was able to repro the same issue in the paired down nvim with minimal config.

liquidz commented 5 years ago

@devth I can reproduce the problem finally!! Do you have :plugins [[cider/cider-nrepl "..."]] in your ~/.lein/profiles.clj?

cider-nrepl plugin injects all cider-nrepl middlewares containing track-state. https://github.com/clojure-emacs/cider-nrepl/blob/v0.20.0/src/cider/nrepl.clj#L511 track-state middleware will send a huge data after requiring namespace, and it take times.

iced command is excluding track-state middleware intentionally. https://github.com/liquidz/vim-iced/blob/0.9.2/clj/iced_repl.clj#L4-L18 So if you have :plugins [[cider/cider-nrepl "..."]] in your ~/.lein/profiles.clj, please delete it.

devth commented 5 years ago

Amazing! Nice job. I will try this out soon. I always thought cider-nrepl was required.. at least it is for the other vim clojure plugins I've tried: acid.nvim and vim-fireplace. 🤔

liquidz commented 5 years ago

@devth Other plugins may require cider-nrepl while iced command injects dependencies automatically. https://github.com/liquidz/vim-iced/blob/0.9.2/deps.edn#L5

I'll fix to work with track-state middleware in the future.

knubie commented 5 years ago

I'm having a similar issue with my shadow-cljs project.

It seems that shadow-cljs includes the cider-nrepl plugin (which includes all the middleware) when cider/cider-nrepl is detected in your dependencies.

At the moment there's no way to turn this feature off.

liquidz commented 5 years ago

FYI https://github.com/thheller/shadow-cljs/blob/2.8.19/src/main/shadow/cljs/devtools/server/nrepl.clj#L303-L311

knubie commented 5 years ago

@liquidz After speaking to the maintainer of shadow-cljs on slack, you can now disable the automatic inclusion of cider middleware as of 2.8.20!

I just tried it out and the delay is gone now.

liquidz commented 5 years ago

@knubie Wow! That's awesome!! Thanks for your reporting!

liquidz commented 4 years ago

Closed by branching to #170 Feel free to reopen this issue 😃