nvim-neotest / neotest

An extensible framework for interacting with tests within NeoVim.
MIT License
2.35k stars 115 forks source link

fzf floating window hangs/is slow to start after running Python tests #78

Closed rouge8 closed 2 years ago

rouge8 commented 2 years ago

I'm not sure if this is a neotest or neotest-python issue, so I decided to open it here. I'm using fzf and fzf.vim with a GitFiles command:

command! -bang -nargs=? -complete=dir GitFiles
      \ call fzf#vim#files(FugitiveWorkTree(), fzf#vim#with_preview({'source': 'git ls-files || fd --type f'}), <bang>0)
nnoremap <C-p> :GitFiles<Cr>

After running neotest.run.run() or neotest.run.run(vim.fn.expand("%")), the fzf floating terminal window takes 10-15 seconds to populate after the window appears. Navigating the window also lags by seconds once it opens, but if you wait the lag disappears. I can reproduce this on any Python file in my work repository, but not a Rust file in the same repository.

rouge8 commented 2 years ago

I was able to reproduce it in the Django repo: https://recordit.co/xMyHPQATnE My guess is it's something to do with the number of tests or files in the project...

rouge8 commented 2 years ago

It looks like adapter.discover_positions() is called on ~every test file in the repo, I wonder if that's related...

stevearc commented 2 years ago

Likely the same issue I had with large repos in #13. Try setting discovery.enabled = false. You lose the ability to see and run all tests, but it should fix the perf issue.

rcarriga commented 2 years ago

I've done a quick check myself and didn't see any slowdown with running other than a lot renders when the summary window was open (which should be fixed now). Is it just fzf that slows down or the entire Neovim instance?

It looks like adapter.discover_positions() is called on ~every test file in the repo, I wonder if that's related...

Can you open the summary window instead of running tests to see? This will isolate discovery from running tests.

I also had pyright absolutely tank my instance while processing, can you double check LSP isn't slowing things down as well?

rouge8 commented 2 years ago

Is it just fzf that slows down or the entire Neovim instance?

The entire Neovim instance is slow while the test runs, but the FZF window is still slow after it finishes.

Can you open the summary window instead of running tests to see? This will isolate discovery from running tests.

Opening FZF after the test summary is a little slow, maybe 1-2 seconds, but not as slow as after the tests.

I also had pyright absolutely tank my instance while processing, can you double check LSP isn't slowing things down as well?

After stopping the LSP with :LspStop and running Neotest on the nearest test, FZF takes 4-5 seconds to open.

rouge8 commented 2 years ago

Likely the same issue I had with large repos in #13. Try setting discovery.enabled = false. You lose the ability to see and run all tests, but it should fix the perf issue.

This seems to fix the issue.

rcarriga commented 2 years ago

OK I'll close this then as it seems to be as it's the same underlying issue :+1:

rcarriga commented 2 years ago

May have spoken too soon on this being the same issue. I noticed a slow down due to the diagnostic consumer when tests completed. I've fixed it in the latest commit if you want to see if that helps

rouge8 commented 2 years ago

Hmm nope, the FZF terminal still takes 10-15 seconds to open after running a test once I re-enable discovery.

rcarriga commented 2 years ago

I was thinking you were using the neotest-python adapter with django but then remembered django has it's own test runner. Are you using neotest-vim-test instead?

rouge8 commented 2 years ago

I was using pytest to run the Django tests. I also use pytest in the work project.

rcarriga commented 2 years ago

Can you share how to do that? I've no experience with Django and a quick skim of the docs aren't very helpful :sweat_smile:

rouge8 commented 2 years ago

Oh, I misremembered! It didn't actually discover any tests, but that was still enough to reproduce the issue as you can see in the recording I posted above.

rcarriga commented 2 years ago

OK that makes more sense thanks :+1: