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

Add resolve timeout for accepting #627

Open
2 tasks done
datwaft opened this issue Dec 17, 2024 · 9 comments
Open
2 tasks done

Add resolve timeout for accepting #627

datwaft opened this issue Dec 17, 2024 · 9 comments
Labels
accept Applying a completion item to the buffer bug Something isn't working

Comments

@datwaft
Copy link

datwaft commented Dec 17, 2024

Make sure you have done the following

  • I have updated to the latest version of blink.cmp
  • I have read the README

Bug Description

I have a big (around 40k lines of code) Playwright project which heavily uses test fixtures which have a noticeable effect on the performance of the LSP server for TypeScript.

I have noticed lag after accepting a completion item, it takes around 1 or 2 seconds and any text written after accepting the completion item is removed when the completion item is inserted.

The wait for the completion items to show up in the completion list is expected (I also have the same issue with nvim-cmp which is probably the fault of the LSP) but the lag after accepting a completion item in which I cannot write anything because it will be removed after the completion item is inserted seems like an issue with blink.cmp (I haven't seen it when using nvim-cmp).

Here is a recording of the issue:

Screen.Recording.2024-12-17.at.14.09.55.mov

Relevant configuration

You can see my configuration here: https://github.com/datwaft/nvim.conf/blob/d834a1b01457ddcb34f6644efd1caa345d1182e4/lua/packages/completion.lua

If it is relevant I am accepting with <space> and have the following completion configuration:

completion = {
  list = {
    selection = "manual",
  },
  accept = {
    auto_brackets = {
      enabled = false,
    },
  },
},

neovim version

NVIM v0.11.0-dev-1369+gb03e790cdd

blink.cmp version: branch, tag, or commit

main (c3ef922)

@datwaft datwaft added the bug Something isn't working label Dec 17, 2024
@Saghen Saghen changed the title [BUG] Lag when accepting a completion item Lag when accepting a completion item Dec 17, 2024
@Saghen Saghen added the accept Applying a completion item to the buffer label Dec 17, 2024
@Saghen
Copy link
Owner

Saghen commented Dec 17, 2024

When you get the chance, open ~/.local/share/nvim/lazy/blink.cmp/lua/completion/accept/init.lua and check how long the .resolve call takes. You can use vim.uv.hrtime() to get the current time (in nanoseconds)

@datwaft
Copy link
Author

datwaft commented Dec 17, 2024

I modified ~/.local/share/nvim/lazy/blink.cmp/lua/blink/cmp/completion/accept/init.lua like this:

image

Here are some of the results:

It took 17583 nanoseconds for `accept`
It took 19333 nanoseconds for `accept`
It took 52500 nanoseconds for `accept`
It took 834666 nanoseconds for `accept`
It took 834750 nanoseconds for `accept`
It took 751750 nanoseconds for `accept`
It took 1170625 nanoseconds for `accept`

Because of how the printed time is growing I think I am doing something wrong, any suggestions?

@datwaft
Copy link
Author

datwaft commented Dec 17, 2024

Btw, I haven't tried the new commit. I am going to use it and see if it helps.

@Saghen
Copy link
Owner

Saghen commented Dec 17, 2024

Sorry I should've clarified, put the print inside the :map. It seems likely that new commit will help reduce the delay, although it may not fully get rid of it

@datwaft
Copy link
Author

datwaft commented Dec 17, 2024

Here are some results (with the new commit):

It took 2109791 nanoseconds for `accept`
It took 1920208 nanoseconds for `accept`
It took 1444042 nanoseconds for `accept`
It took 1561542 nanoseconds for `accept`
It took 2257792 nanoseconds for `accept`
It took 2500791 nanoseconds for `accept`
It took 1195458 nanoseconds for `accept`
image

@datwaft
Copy link
Author

datwaft commented Dec 17, 2024

NOTE: I am still seeing the lag sometimes.

@Saghen
Copy link
Owner

Saghen commented Dec 17, 2024

Haha, once again I should've clarified 😂 The start_time should be before the .resolve and the end_time should be inside the :map so we can see how long that async call takes. Sorry for the back and forth on this

@datwaft
Copy link
Author

datwaft commented Dec 17, 2024

😅 🤣

Here are the new results:

It took 408560458 nanoseconds for `accept`
It took 824164041 nanoseconds for `accept`
It took 346669333 nanoseconds for `accept`
It took 25417 nanoseconds for `accept`
It took 1018236167 nanoseconds for `accept`
It took 363493625 nanoseconds for `accept`
image

@Saghen
Copy link
Owner

Saghen commented Dec 18, 2024

It seems like nvim-cmp skips the resolve if it takes more than 80ms by default, whereas yours are taking up to 1s

@Saghen Saghen changed the title Lag when accepting a completion item Add resolve timeout for accepting Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accept Applying a completion item to the buffer bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants