roxma / ncm-clang

DEPRECATED use https://github.com/ncm2/ncm2-pyclang instead
29 stars 4 forks source link

On the performance of ncm-clang #3

Open harrysummer opened 6 years ago

harrysummer commented 6 years ago

Dear owner, Thanks for providing us such a good plugin for Neovim! I appreciate your work deeply!

However, during my everyday usage of this plugin, I'm really distracted by the significant lag. And I would like to discuss with the community of the performance of ncm-clang. In my current project with more than one hundred of header files, YouCompleteMe gives result in around 1 second, while ncm-clang is around 5 second. I'm not sure what the reason is, but from what I have seen, I doubt the lag roots in the architecture of ncm-clang.

I was using YouCompleteMe for a long time. YouCompleteMe is a great project, except it's hard to compile on non-standard systems, e.g., MSYS2 on Windows. It needs to link with boost and libclang in order to work. And it finally generates a server-side binary for interacting with libclang, and a client-side python library which is loaded when a c/cpp file is opened. So, once a completion request is posted, vim could invoke the function in python client, and the client would send async request to the server. This work flow is high efficient in OS point-of-view, because the server is a persistent process, and OS may be able to cache the headers for the process. And no dynamic library or executables needs to be loaded in every completion.

On the other hand, what I see from my limited usage of ncm-clang is that, it calls clang every time when a completion request is emitted. Though this make it easier for installing the plugin (need not to build against libclang, etc), it slows down the processing of completion, with the overhead of a lot loading and initialization works per completion.

roxma commented 6 years ago

I don't think re-spawning a subprocess every time is the bottle-neck, though.

It may be slower, but it shouldn't make it being 5 second vs 1 second.

harrysummer commented 6 years ago

I am sort of busy these days. I will do a profiling when I have time.

roxma commented 6 years ago

FYI, I have updated the README, since ALE is taking too much CPU resource

    " (optional, for completion performance) run linters only when I save files
    let g:ale_lint_on_text_changed = 'never'
    let g:ale_lint_on_enter = 0
roxma commented 6 years ago

copied from https://github.com/roxma/clang_complete/issues/1

After some more test,

I noticed that the completion gets really fast after caching the TU and an extra explicit reparse.

I don't know why it needs an explicit reparse.

current experimental repo: https://github.com/ncm2/ncm2-libclang

I'm going to test the python binding again, since it's more handy and easier to setup and the official libclang python binding now supports python3.

roxma commented 6 years ago

https://github.com/ncm2/ncm2-pyclang deprecates this repo

roxma commented 6 years ago

I have a .cpp file that includes the bloated boost and opencv headers,

With libclang.so, it takke about 0.2s after the TU is cached and reparsed.

With clang binary, it taks about 3-5 seconds to generate completions.

This is good. However, the clang binary seems to be more robust for completions. For example,

#include <string>
#include <iostream>

using namespace std;

int main() {
        string foobar;
        foo
        foobar.|
}

The clang binary generates the right suggestions, but ncm2-pyclang doesn't. I'm not sure what's wrong with ncm2-pyclang.