vim-clang-format icon indicating copy to clipboard operation
vim-clang-format copied to clipboard

the source file much longer, the :ClangFormat runs much longer

Open buptjamin opened this issue 6 years ago • 3 comments
trafficstars

slow problem when the source file was long/big. for example: any source file 1000+ lines

buptjamin avatar May 12 '19 06:05 buptjamin

use https://github.com/google/vim-codefmt now!

buptjamin avatar May 12 '19 06:05 buptjamin

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.

rhysd avatar May 15 '19 02:05 rhysd

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().

Kypert avatar Apr 11 '20 13:04 Kypert