TommyX12 / company-tabnine

A company-mode backend for TabNine, the all-language autocompleter: https://tabnine.com/
MIT License
686 stars 52 forks source link

The longer you use it, the laggier it gets #45

Open MatthewZMD opened 3 years ago

MatthewZMD commented 3 years ago

I don't know if this is duplicate of #39 or company-mode/company-mode#1056 , but similar issue.

In a newly opened Emacs, company-tabine works like magic and super fast, there is no performance issues at all.

However after using it intensively for hours, regardless of in single or multiple files, the completion gets extremely slow and lag literally on every input. htop shows tabnine process takes up quite a bit of memory, and executing M-x company-tabnine-restart-server or TabNine::restart doesn't fix the issue. Restarting Emacs makes tabnine works great again.

Emacs 28 gccemacs, manjaro, config

randomwangran commented 3 years ago

Same phenomenon and I end up restarting Emacs much often.

MatthewZMD commented 3 years ago

ping @TommyX12

TommyX12 commented 3 years ago

Hey Matthew, sorry to hear about this issue. Unfortunately I wasn't able to reproduce this; it works as fast as a newly opened emacs even when my emacs-uptime is 16+ days :( (I am using Emacs 26.2 on MacOS)

The next time it gets laggy, could you try to use the CPU profiler to see which part of the tabnine client is being the bottleneck? I will try to pinpoint the issue. Thanks!

randomwangran commented 3 years ago

After an update to 3.3.57, I find myself unable to reproduce the issue. I will keep an eye on it and next time when there is a problem I will use a CPU profiler to make a detailed report.

randomwangran commented 3 years ago

Sorry for bothering again.

I just experienced such a laggy again. The issue is my Emacs is almost frozen thus no way that I can do to investigate this issue.

Due to the nature of this issue, i.e., intermittency. It's really hard to create an environment to reproduce the issue.

What I observe that this update version 3.3.57, can somehow solve the laggy issue by itself.

MatthewZMD commented 3 years ago

The next time it gets laggy, could you try to use the CPU profiler to see which part of the tabnine client is being the bottleneck? I will try to pinpoint the issue. Thanks!

I'm currently experiencing lag again, apparently Automatic GC is taking up quite a bit of CPU. Could you share your gc-cons-threshold with me?

randomwangran commented 3 years ago

Automatic GC is taking up quite a bit of CPU

Does this coincide? Today, I experience it again and I studied the CPU profile. I found GC is the most CPU consumer.

;;;; GC issue
(add-hook 'after-init-hook (lambda () (setq gc-cons-threshold 100000000)))
(add-hook 'focus-out-hook 'garbage-collect)

I currently have no laggy issue with this update but will keep an eye on it.

TommyX12 commented 3 years ago

I'm currently experiencing lag again, apparently Automatic GC is taking up quite a bit of CPU. Could you share your gc-cons-threshold with me?

My gc-cons-threshold is 200000000. Good to hear that it at least mitigated the issue.

randomwangran commented 3 years ago

After the update the GC threshold, I find most of the time there is no issue.

However, I find sometimes Emacs will be frozen and reject any command. The message shows the following information:

TabNine process #<process company-tabnine--process> received event "exited abnormally with code 1".

Restarting TabNine process.

It is unclear what causes the restarting process of TabNine.

I was wondering if it is possible to make starting process as asynchronous process.

MatthewZMD commented 3 years ago

I was wondering if it is possible to make starting process as asynchronous process.

I looked at the codebase, there is a commented company-tabnine-async variable and a TODO: should we use async or not.

@TommyX12 What's stopping you guys from using async?

otavioschwanck commented 3 years ago

Maybe a good way is implement tabnine com https://github.com/emacs-lsp/lsp-mode as a language server, with this, the process run asynchronous, not depending on emacs

MatthewZMD commented 3 years ago

This is a great idea

einSelbst commented 3 years ago

Maybe a good way is implement tabnine com https://github.com/emacs-lsp/lsp-mode as a language server, with this, the process run asynchronous, not depending on emacs

Would this mean I have to choose between either tabnine or say, jsts-language-server? Because, I want both.

liar666 commented 2 years ago

Same problem here. GC solution does not seem to work.

I'm working with emacsclient on an org file with company-tabnine (+other company backends) and I have to kill emacs client & server very often (~15min) :{ company-TabNine is clearly the problem as deactivating it in my .emacs make everything running smooth again.

I've tried killing TabNine/WD-TabNine processes, but they automatically spawn again, and Emacs/client get even more laggy...

The next time it gets laggy, could you try to use the CPU profiler to see which part of the tabnine client is being the bottleneck? I will try to pinpoint the issue. Thanks!

Can someone tell me how to "use the CPU profiler", so that I can find where is the problem on my side?

tillydray commented 9 months ago

@liar666 and others

Can someone tell me how to "use the CPU profiler", so that I can find where is the problem on my side?

  1. M-x profiler-start
  2. Choose cpu
  3. do something that causes an issue
  4. M-x profiler-stop
  5. M-x profiler-report
  6. Click into everything. You're looking for a large jump in %. Whatever process caused the large jump is usually the problem process