equalsraf / neovim-qt

Neovim client library and GUI, in Qt5.
https://github.com/equalsraf/neovim-qt/wiki
ISC License
1.85k stars 171 forks source link

Doing a loop of getchar(1) causesit to hang #605

Open eyalk5 opened 5 years ago

eyalk5 commented 5 years ago

Hi,

as witnessed in LeaderF, when doing

while(1): 
     let x=getchar(1)
     if !type(nr) && nr == 0:
         continue
     HANDLE input

neovim-qt (with latest neovim server on macos) hangs (from time to time). Especially, it hangs when many keys are sent at once.

That is, it stops handling keys until one cause it to redraw (for example, change the size). This behavior is present in last version of LeaderF . The solution is sleep. It seems to be a thread starvation issue.

equalsraf commented 4 years ago

Interesting.

Did a quick test here in vimscript

function! Wat()
    while 1 == 1
         let x=getchar(1)
         "if !type(nr) && nr == 0:
        "    continue
        "HANDLE input
    endwhile
endfunction

I do see a spike in cpu consumption (in nvim) but no thread variation in either nvim or nvim-qt. The UI blocks with the cursor on the corner and no rendering happens even with a resize.

Using getchar() avoids the cpu comsumption but still blocks rendering (not surprising).

I thought this was supposed to work (https://github.com/neovim/neovim/pull/5384) but maybe I was wrong.

PS: funny bit - this also happens with vim-gtk.