cmp-rg icon indicating copy to clipboard operation
cmp-rg copied to clipboard

feat: use vim.uv.spawn instead of vim.fn.jobstart

Open delphinus opened this issue 1 year ago • 2 comments

The current code uses vim.schedule_wrap to call vim.fn.jobstart for running rg. This can be replaced by uv.spawn that can be called “in fast event”. This makes it run rg as soon as cmp starts to complete.

But this change has 2 problems.

  • vim.fn.json_decode cannot be called in fast event. We should always use vim.json.decode, so we must remove support for Neovim older than v0.6.
  • uv.spawn always run a process directly (without shell). Now additional_arguments option should be an array instead of string.

I think benefits we can get by this change are larger than these breaking changes.

delphinus avatar Feb 23 '24 14:02 delphinus

Does this actually make a different to the performance? Can you profile this?

lukas-reineke avatar Mar 18 '24 03:03 lukas-reineke

I simply test by record duration between begining of complete() and where callback being called, it was 150ms before and 50ms now in init.lua file with debounce of 0.

The difference is vim.schedule_wrap is delayed by 100ms(depends on cmp bussyness) to start the job

xzbdmw avatar Jun 22 '24 19:06 xzbdmw