Sarcasm / flycheck-irony

C, C++ and Objective-C support for Flycheck, using Irony Mode
56 stars 10 forks source link

Slow checking - is it normal? #17

Closed dmalyuta closed 7 years ago

dmalyuta commented 7 years ago

I'm working on a modestly sized C++ project. flycheck-irony works well, the syntax checking is asynchronous however it takes about 10 seconds for flycheck to update its error highlights in the buffer. Between purposefully introducing a syntax error and the error being shown by flycheck, I see FlyC* in the mode line and in the system monitor irony-server sometimes uses up to 400 MiB RAM and 8% CPU. Is this normal behavior?

Sarcasm commented 7 years ago

It might be the normal behavior, or at least, you are not alone.

I can notice very slow syntax check for some files too (or maybe they get slower?), never investigated this/ It's possible something is wrong somewhere. To get a quick idea, it is possible to measure libclang time, to see if it's where all the time is spent. Even if the work happens in libclang, it could be some configuration issue.

Personally, I actually kill my irony-server from time to time when I observe that the memory consumption becomes too high...somehow I restart Emacs enough often that it does not bother me so much but it's not really an acceptable behavior.

dmalyuta commented 7 years ago

I see. Just two questions then:

  1. How would I measure libclang time?
  2. Why would restarting Emacs "often enough" help?
Sarcasm commented 7 years ago
  1. When a syntax check is triggered by flycheck, 2 requests are emitted to irony-server. The first is a Irony::parse() request. This in turn calls TUManager::parse(), which apart from the first time call, or if the compile options changed, should only call clang_reparseTranslationUnit(). This libclang function is supposed to be where the time is spent, other stuff is just glue code.

The second request, ask for the Irony::diagnostics() of the previous parse, this is supposed fast except maybe if there is an enormous amount of diagnostics.

Then you can add timings in https://github.com/Sarcasm/irony-mode/blob/bfe703a4c0e91a960c606bf2420b1f118e53a0a6/irony-diagnostics.el or https://github.com/Sarcasm/flycheck-irony/.

If the time spent from elisp side minus the time spent in Clang is noticeably different, then something is wrong.

  1. irony-mode starts irony-server on-demand. The first time a request is made (completion, syntax-check), the server is checked. If the executable does not exist the user is suggested to install it, if the executable is not running it is started, ...The irony-server process is started as a subprocess of the emacs instance, Emacs is the parent process. When you kill Emacs, the child process, irony-server, is automatically killed (that frees memory).

In this configuration, the lifetime of irony-server is necessary a subset of Emacs lifetime.

dmalyuta commented 7 years ago

Ok, thanks for explaining :)