Skip to content

Commit

Permalink
@ perf: avoid source slowdown due to unnecessary context switches #2060
Browse files Browse the repository at this point in the history
  • Loading branch information
iguanacucumber committed Oct 13, 2024
1 parent 11493a5 commit 63d7acd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lua/cmp/source.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ source.get_entries = function(self, ctx)
---@type cmp.Entry[]
local entries = {}
local matching_config = self:get_matching_config()
for _, e in ipairs(target_entries) do
for i, e in ipairs(target_entries) do
local o = e.offset
if not inputs[o] then
inputs[o] = string.sub(ctx.cursor_before_line, o)
Expand All @@ -145,9 +145,14 @@ source.get_entries = function(self, ctx)
entries[#entries + 1] = e
end
end
async.yield()
if ctx.aborted then
async.abort()

-- Yield to event loop once in a while to avoid UI freezes
-- But avoid yielding too often causing too many context switches
if i % 1000 == 999 then
async.yield()
if ctx.aborted then
async.abort()
end
end
end

Expand Down
1 change: 1 addition & 0 deletions merged.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
> Therefore these PRs won't have a patch file for them in the PRs folder (this folder contains unedited patch files from PRs from nvim-cmp)
## Perf
- @ perf: avoid source slowdown due to unnecessary context switches #2060
- perf: improve for source providing huge list of items #1980
- perf: use builtin for key normalization #1935
- Do not use sync code in InserEnter #1911
Expand Down

0 comments on commit 63d7acd

Please sign in to comment.