daa84 / neovim-lib

Rust library for Neovim clients
GNU Lesser General Public License v3.0
192 stars 26 forks source link

Passing values by reference? #11

Closed KillTheMule closed 7 years ago

KillTheMule commented 7 years ago

Hey, one quick(?) question. I came about this call, which I'm working with for my neovim rpc plugin. Is there a reason you're passing the values by reference? As far as I can see, both method and params go out of scope anyways after that. Wouldn't it be better than to pass them by value?

The reason I'm asking is that in my case params will be quite large, and if passed by reference I will have to do quite a bit of copying to keep the data in my addon. I you move the values here, I can simply take ownership and be done with it.

daa84 commented 7 years ago

This pass by ref is only to not make copy of data. As i understand move semantics it still copy some amount of stack data in case of function call. Maybe here is not big problem to use move. Only problem is that this breaks backward compatibility .

KillTheMule commented 7 years ago

You can see a bit of discussion here: https://www.reddit.com/r/rust/comments/79ydaa/array_of_strings_move_or_clone/

That's exactly my use case, where move is very clearly much more performant than references. Maybe there's a way to offer both variants and let the library user decide?

daa84 commented 7 years ago

I think it is better to just use 'move', funny thing as that in my code i also use clone after take reference 😄 , so it looks like 'move' is better solution. Also move don't do to much copy in case of Value i think.

daa84 commented 7 years ago

Thanks for report, this helps fix number of clone problems 👍