Non-Blocking Vim

A few weeks ago, I wrote about Thiago Arruda's multithreaded Vim port. A reader sent in a link to Thiago's second attempt which changes the approach.

Rather than threads, it uses a job manager that polls for I/O events. If I understand the patch correctly, it uses select with a zero timeout to multiplex I/O, then poll for the results.

Internally, polling is done in a function that replaces ui_inchar and interrupts the blocking wait every 100 milliseconds to check for job activity. When a job sends some data, it returns a special key code to the calling loop, which will trigger the autocommand, similar to how the CursorHold event is implemented.

The advantage of this approach is it avoids some of the issues the author discovered with threads and Vim. Also, it should allow other scripting language runtimes to integrate with Vim without depending on linking against them at compilation time.

I've spent some time looking at Node and uv's internals before, and I really like the idea of Vim being more like uv. This patch doesn't do exactly that, but I think it's an interesting development that deserves support.

blog comments powered by Disqus