Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vim's job_start() does not work in MacVim and causes high CPU #272

Closed
airblade opened this issue Apr 28, 2016 · 7 comments
Closed

Vim's job_start() does not work in MacVim and causes high CPU #272

airblade opened this issue Apr 28, 2016 · 7 comments

Comments

@airblade
Copy link

airblade commented Apr 28, 2016

Steps to reproduce:

  • Given the file demo.vim:
call ch_logfile('channel.log', 'w')

function! OutHandler(channel, msg)
  echom 'OutHandler: '.a:channel.' :: '.a:msg
endfunction

call job_start('ls', {'out_cb': 'OutHandler'})
  • Execute in mvim: mvim -u NONE -U NONE -N -S demo.vim.
  • Inspect messages with :messages.
    • Expected: a line like OutHandler: channel 0 open :: FILE for each file in the current directory, followed by OutHandler: channel 0 closed :: DETACH.
    • Actual: no messages.
  • Inspect the channel log with cat channel.log (in the shell).
    • Expected:
==== start log session ====
  0.000027 : Starting job: ls
  0.000064 on 0: Created channel
  0.000522 : looking for messages on channels
  0.002943 RECV on 0: 'channel.log
<ONE LINE FOR EACH FILE>
'
  0.002994 on 0: Invoking channel callback OutHandler
  <DITTO FOR EACH FILE>
  0.003437 ERR on 0: channel_select_check(): Cannot read from channel
  0.003445 PUT on 0: 'DETACH
'
  0.003447 on 0: Closing channel
  0.003465 : looking for messages on channels
  0.003470 on 0: Invoking channel callback OutHandler
  0.568784 : looking for messages on channels
  • Actual:
==== start log session ====
  0.000031 : Starting job: ls
  0.000080 on 0: Created channel
  • Inspect the CPU (open ActivityMonitor and filter for 'vim') while you leave MacVim open.
    • Expected: CPU for the Vim and MacVim processes remains under 1%.
    • Actual: over 10s or so CPU for both processes rises to 10%-20%.

The messages and channel log show that the out_cb callback is never called. For some reason MacVim never starts to look for messages on the channels.

Compare this to mvim -v where everything works as expected.

I'm using MacVim 7.4.1795 built with Homebrew.

@jpetrie
Copy link
Contributor

jpetrie commented Apr 29, 2016

My gut feeling is that this all-new jobs/channels stuff in core vim (which I've not had a chance to look at much since it doesn't interest me) is causing the backend vim process that MacVim runs to do things that stimulate messages to our frontend process at times where we didn't expect them, resulting in sadness.

@splhack
Copy link
Contributor

splhack commented Apr 29, 2016

the root cause is, I guess, NetBeans support in MacVim. It has not been maintained anymore. And I'm the author of the patch😄 . I'll remove it and test it.

@splhack
Copy link
Contributor

splhack commented May 7, 2016

Fixed in #278, but still make test with $(VIMPROG) -g sometimes fails a few of tests.

@airblade
Copy link
Author

airblade commented May 9, 2016

I tested again with MacVim 7.4.1825 built via Homebrew.

  • I never get any messages in :messages.
  • Sometimes the channel log shows the output of the ls in the job; usually it doesn't.
  • The close_cb handler is never called.
  • The CPU processes remain low, as expected.

The log looks like this when the job's output is logged:

==== start log session ====
  0.000030 : Starting job: ls
  0.000082 on 0: Created channel
  0.014462 RECV on 0: 'Capfile
Gemfile
Gemfile.lock
README
Rakefile
app
channel.log
config
config.ru
db
demo.vim
doc
features
lib
log
private
public
script
spec
test
tmp
vendor
'
  0.014508 ERR on 0: MMChannel_read(): Cannot read from channel
  0.014528 on 0: Closing channel

And like this when the job's output isn't logged:

$ cat channel.log
==== start log session ====
  0.000030 : Starting job: ls
  0.000065 on 0: Created channel
  0.018400 ERR on 0: MMChannel_read(): Cannot read from channel
  0.018431 on 0: Closing channel

Using mvim -v ... everything works as expected.

Having said all that, when I run jobs asynchronously in vim-gitgutter with the MacVim GUI, they now work :)

@airblade airblade changed the title Vim's job_start() does not work in MacVim and causes high CPU Vim's job_start() does not work in MacVim and causes high CPU May 9, 2016
@splhack
Copy link
Contributor

splhack commented May 10, 2016

I have no idea about your demo.vim is correct or not. At least, current master has no issues in src/testdir/test_channel.vim.

@ruedigerha
Copy link

I was having the same problem, and it persists for me on master.

I noticed this with the "dein" plugin manager when trying to update plugins. In the GUI, the first eight jobs get started (invoking git), but no job reports results, so the updating stalls at that point. It works fine in the terminal (and in gVim on Windows, too). The logs look pretty much like those posted by airblade.

@splhack splhack mentioned this issue May 16, 2016
@airblade
Copy link
Author

I confirm this solves the problem for me. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants