hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
8.16k stars 406 forks source link

perf: avoid source slowdown due to unnecessary context switches #2060

Closed jasonchoimtt closed 1 month ago

jasonchoimtt commented 1 month ago

Hello. I faced some completion performance issue, and I ended up tracking down a performance issue in cmp/source.lua.

The loop in question loops over all completion entries to perform filtering, so it is quite a tight loop. However, it yields to the event loop after every iteration. I think it results in too many context switches, slowing down the code.

Sorry that I don't have a good repro for this, by FWIW, in my own case making this change improves latency observably, when using the cmp-buffer source with a large number of words.

iurimateus commented 1 month ago

I think https://github.com/hrsh7th/nvim-cmp/pull/1980 would solve it. (or https://github.com/yioneko/nvim-cmp/tree/perf)

iguanacucumber commented 1 month ago

1980 introduce more caching however it still yields after every iteration so i think that not yielding every time is a good thing

jasonchoimtt commented 1 month ago

Thanks, appreciate the work!