Open prabirshrestha opened 5 years ago
Current trend seems to be to offload the heavy processing to external processes, e.g. LSP. Which makes sense as well when thinking of mobile platforms. But maybe WebWorkers API can still come in handy, I will have a closer look.
Especially since the world model of Vim seems to be single-threaded, and the Vim OS interface does not expose threads either. Also, the good old select() loop has finally got a nice API with await :)
Problem with external process is it gets chatty and using single thread like node also doesn't scale well when you need perform heavy calculations.
Here are few examples:
I still think it could be possible to have both worker and process and let the plugin authors decide what they want.
I agree, I have also been thinking about having simple LSP servers running inside Vim, for example something that replicates C-x C-n. I can see the use case for worker threads, and they should be available on most modern architectures and implementation should not be too hard if the interactions between worker threads and the main thread are sufficiently restricted (e.g. via sockets/pipes or something similar). Duktape easily supports multiple execution contexts, and even the same context active on multiple threads as long as two threads don't trigger automatic memory management at the same time. Of course this probably wouldn't work on Amiga or VMS ;)
Plugin authors can easily use globalThis.WebWorker
to check if web worker exists or not.
Basic functionality is there on Linux/MacOS, give it a spin if you are on one of those platforms.
... and Windows, Win64 binaries at https://github.com/bobpepin/vim/releases/tag/duk-win64-20190419T182100. To try (after putting Babel files into runtimepath)
:so lsp.vimrc
:dukfile workertest.js
wait until connected, then
:duk worker.postMessage("FOO"); Promise.runQueue()
This is awesome. I will be out for weeks on vacation. Would love to try this soon.
@bobpepin any plans to send an initial path to the upstream vim? I also filed an issue for wasm support in vim https://github.com/vim/vim/issues/4604. Wondering if that would be better since that would allows us to write in any language.
No immediate plans to submit to the upstream Vim, since I am quite busy with other things these days. The thing with only wasm is that it would either mean not having a REPL/Notebook interface or Vim would have to ship a compiler from some language to wasm. Also as far as I am aware the GC interface for wasm is still work in progress.
useful for plugins to implement heavy processing such as fuzzy search.
Also need to implement TransferrableObjects for perf if possible. https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers#Passing_data_by_transferring_ownership_(transferable_objects)