vim-clang-format
vim-clang-format copied to clipboard
the source file much longer, the :ClangFormat runs much longer
slow problem when the source file was long/big. for example: any source file 1000+ lines
use https://github.com/google/vim-codefmt now!
vim-codefmt also overwrites entire buffer with formatted output. So I don't know what causes the performance issue on your environment. https://github.com/google/vim-codefmt/blob/master/autoload/codefmt/clangformat.vim#L121
Please let me know the pre-condition (OS, Vim version) and how to reproduce it if you're still interested in this plugin. Otherwise I will close this issue since I cannot investigate further.
Switched to google/vim-codefmt for a while, but wanted to come back to this plugin. Culprit in my case seems to have been foldmethod=syntax, please see investigation below.
Using my casual +10k lines C-file, I started the profiler to see what took time:
FUNCTIONS SORTED ON TOTAL TIME
count total (s) self (s) function
1 17.694369 16.049015 clang_format#replace()
1 1.645128 0.003329 clang_format#format()
1 1.641716 0.000726 <SNR>74_system()
...
In clang_format#replace(), the call to setline(1, splitted) took about 16s.
Found a similar issue on setline() here https://github.com/dense-analysis/ale/issues/1829.
By installing Konfekt/FastFold, the time spent in clang_format#replace() went down to 0.006350s.
If I understand correctly, google/vim-codefmt does replace the buffer too (maktaba#buffer#Overwrite()), but in my case I ended up using the python implementation to work on the diff-chunk, avoiding their call to setline().