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

Python plugin execution speed #4522

Closed
unphased opened this issue Apr 3, 2016 · 3 comments
Closed

Python plugin execution speed #4522

unphased opened this issue Apr 3, 2016 · 3 comments
Labels
closed:question issues that are closed as usage questions performance issues reporting performance problems

Comments

@unphased
Copy link

unphased commented Apr 3, 2016

Hi guys, I have written some moderately elaborate python code for Vim, and I have found that vanilla vim runs my python code a little bit less than one hundred times faster than in neovim.

The code can be found starting here.

Now I'm using the python << EOF method of writing the python, and I havent refactored it out into its own plugin yet. it's still all quite experimental.

But I'm just flabbergasted by the amount of performance difference and I wonder if maybe vim is compiling the python and neovim is for whatever reason always interpreting it?

Even still I'm not really doing enough work to justify it spending so much time.

Looking for tips on how to continue debugging this.

@bfredl
Copy link
Member

bfredl commented Apr 3, 2016

for line in win.buffer is correct, it fetches the entire buffer once. The problem might be the win.width inside the innermost (line) loop. If you move it out before the loop (width = win.width, as already is done for height), does the difference decrease?

@ZyX-I
Copy link
Contributor

ZyX-I commented Apr 3, 2016

@unphased Vim contains embedded interpter. I.e. it links with libpython and vim.* objects directly call C code. Neovim uses msgpack-rpc so anything like vim.buffer.__getitem__(1) (vim.buffer[1]) is doing “form request -> serialize it in msgpack -> deserialize it on Neovim side -> form the response -> serialize it -> deserialize on the Python side”. Plus the OS doing context switches because Python interpreter is one process and Neovim is another. In Vim this is “convert Python object to Vim -> call some C functions -> convert return value of C functions to Python”, and no necessary context switches. This has nothing to do with compiling/interpreting: libpython is the same both in Vim and Neovim cases. But this is IPC that slows down things which is never going to be just as fast, main optimization strategy here is reducing the number of requests (like suggestion by @bfredl).

@justinmk justinmk added closed:question issues that are closed as usage questions performance issues reporting performance problems labels Apr 3, 2016
@justinmk justinmk closed this as completed Apr 3, 2016
@unphased
Copy link
Author

unphased commented Apr 3, 2016

Just following up, I think you guys found it. With win.width cached outside the inner loop, performance is very comparable now.

ZyX also wrote a nice answer for my question here which does impact this loop though, I will need to bring it out of python now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:question issues that are closed as usage questions performance issues reporting performance problems
Projects
None yet
Development

No branches or pull requests

4 participants