vim 插件 慢_对Vim进行性能分析以找出使Vim变慢的插件

vim 插件 慢

Vim is pretty fast and powerful. However, the core of Vim is (yet) single-threaded (some discussions and tries on porting Vim to be multi-threading, but not yet there). This means some functions that are slow will block Vim there and you have to wait for it. While Vim is fast, some plugins are not. When Vim turns to be slow, it is very likely caused by one or more plugins.

Vim非常快速且强大。 但是,Vim的核心是(单线程)(一些讨论并尝试将Vim移植为多线程,但目前还没有。)。 这意味着某些较慢的功能会阻止Vim在那里,您必须等待它。 尽管Vim很快,但有些插件却没有。 当Vim变慢时,很可能是由一个或多个插件引起的。

However, Vim users tend to have a bunch of plugins installed and managed by pathogen, Vindle (my preference, my Vim configs) or manually. Guessing and trying out which plugins are slow from 10s of plugins is no fun. For these situations, the profiling mechanism in Vim will help you out.

但是,Vim用户往往会通过病原体 Vindle (我的偏爱,我的Vim配置 )或手动安装和管理一堆插件。 猜测并尝试从10个插件中慢下来的插件并不有趣。 对于这些情况,Vim中的分析机制将为您提供帮助。

找出哪个插件使Vim启动缓慢 (Find out which plugin makes Vim slow to start)

You can profile the startup process of Vim by adding the --startuptime option during starting Vim as follows.

您可以通过在启动Vim期间添加--startuptime选项来配置Vim的启动过程,如下所示。

vim --startuptime profile.log

One example profile.log is as follows for you reference.

下面是一个示例profile.log,供您参考。

times in msec
 clock   self+sourced   self:  sourced script
 clock   elapsed:              other lines

000.018  000.018: --- VIM STARTING ---
000.113  000.095: Allocated generic buffers
000.188  000.075: locale set
000.193  000.005: window checked
000.593  000.400: inits 1
000.636  000.043: parsing arguments
000.637  000.001: expanding arguments
000.648  000.011: shell init
000.858  000.210: Termcap init
000.877  000.019: inits 2
000.981  000.104: init highlight
001.417  000.142  000.142: sourcing /usr/share/vim/vim74/syntax/syncolor.vim
001.505  000.266  000.124: sourcing /usr/share/vim/vim74/syntax/synload.vim
018.452  000.044  000.044: sourcing /usr/share/vim/vimfiles/ftdetect/stp.vim
018.565  017.026  016.982: sourcing /usr/share/vim/vim74/filetype.vim
018.595  017.396  000.104: sourcing /usr/share/vim/vim74/syntax/syntax.vim
018.633  000.007  000.007: sourcing /usr/share/vim/vim74/filetype.vim
018.689  000.028  000.028: sourcing /usr/share/vim/vim74/ftplugin.vim
018.716  017.704  000.273: sourcing /etc/vimrc
019.066  000.264  000.264: sourcing /usr/share/vim/vim74/ftoff.vim
019.459  000.179  000.179: sourcing /home/zma/.vim/bundle/Vundle.vim/autoload/vundle.vim
019.660  000.137  000.137: sourcing /home/zma/.vim/bundle/Vundle.vim/autoload/vundle/config.vim
038.883  000.076  000.076: sourcing /home/zma/.vim/bundle/omlet.vim/ftdetect/omlet.vim
038.999  000.052  000.052: sourcing /usr/share/vim/vimfiles/ftdetect/stp.vim
039.267  017.721  017.593: sourcing /usr/share/vim/vim74/filetype.vim
...
...
084.542  065.800  046.465: sourcing $HOME/.vimrc
084.557  000.072: sourcing vimrc file(s)
085.672  000.971  000.971: sourcing /home/zma/.vim/bundle/YouCompleteMe/plugin/youcompleteme.vim
100.023  014.292  014.292: sourcing /home/zma/.vim/bundle/AutoTag/plugin/autotag.vim
100.321  000.016  000.016: sourcing /home/zma/.vim/bundle/Syntastic/plugin/syntastic/autoloclist.vim
...
...
114.569  014.046  012.347: sourcing /home/zma/.vim/bundle/Syntastic/plugin/syntastic.vim
115.107  000.470  000.470: sourcing /home/zma/.vim/bundle/taglist.vim/plugin/taglist.vim
117.816  002.652  002.652: sourcing /home/zma/.vim/bundle/The-NERD-tree/plugin/NERD_tree.vim
118.277  000.392  000.392: sourcing /home/zma/.vim/bundle/snipMate/plugin/snipMate.vim
119.694  001.353  001.353: sourcing /home/zma/.vim/bundle/TinyBufferExplorer/plugin/tbe.vim
149.035  029.274  029.274: sourcing /home/zma/.vim/bundle/LustyJuggler/plugin/lusty-juggler.vim
149.397  000.274  000.274: sourcing /home/zma/.vim/bundle/vim-slime/plugin/slime.vim
149.628  000.069  000.069: sourcing /usr/share/vim/vim74/plugin/getscriptPlugin.vim
...
...
152.029  000.491  000.491: sourcing /home/zma/.vim/bundle/snipMate/after/plugin/snipMate.vim
152.097  001.635: loading plugins
152.106  000.009: inits 3
152.510  000.404: reading viminfo
152.519  000.009: setting raw mode
152.538  000.019:start termcap
152.576  000.038: clearing screen
220.202  000.173  000.173: sourcing /usr/share/vim/vim74/ftplugin/c.vim
265.430  000.066  000.066: sourcing /usr/share/vim/vim74/indent/c.vim
310.045  001.924  001.924: sourcing /usr/share/vim/vim74/syntax/c.vim
349.111  000.230  000.230: sourcing /usr/share/vim/vim74/indoff.vim
349.373  194.404: opening buffers
350.037  000.141  000.141: sourcing /usr/share/vim/vim74/ftplugin/c.vim
352.132  001.410  001.410: sourcing /usr/share/vim/vim74/syntax/c.vim
352.761  000.181  000.181: sourcing /home/zma/.vim/bundle/Syntastic/autoload/syntastic/log.vim
353.582  002.477: BufEnter autocommands
353.584  000.002: editing files in windows
354.535  000.865  000.865: sourcing /home/zma/.vim/bundle/YouCompleteMe/autoload/youcompleteme.vim
505.914  000.134  000.134: sourcing /home/zma/.vim/bundle/The-NERD-tree/nerdtree_plugin/exec_menuitem.vim
506.267  000.312  000.312: sourcing /home/zma/.vim/bundle/The-NERD-tree/nerdtree_plugin/fs_menu.vim
506.772  151.877: VimEnter autocommands
506.773  000.001: before starting main loop
511.890  003.069  003.069: sourcing /home/zma/project/vim-config/.vim/bundle/taglist.vim/plugin/taglist.vim
512.093  002.251: first screen update
512.095  000.002: --- VIM STARTED ---

Overall, Vim took around half a second to start. Among the plugins, lustyjuggler and syntastic took the most time to initialize themselves, while both are still fine as they took only 10s of microseconds. If Vim turned to be slow because of some plugins, the suspicious ones will show up in the list with lots time used shown in the profile log.

总体而言,Vim花了大约半秒钟才开始。 在这些插件中,lustyjuggler和syntastic花费了最多的时间来初始化自己,而两者都还不错,因为它们仅花费了10微秒。 如果由于某些插件而使Vim变慢,则可疑插件将显示在列表中,并且配置文件日志中将花费大量时间。

找出哪个插件可使Vim缓慢执行某些操作 (Find out which plugin makes Vim run slowly for certain actions)

Vim also supports profiling of operations during using Vim to help us find out why one operation in Vim is slow.

Vim在使用Vim的过程中还支持对操作进行性能分析,以帮助我们找出为什么Vim中的一项操作比较慢。

First, enable the profiling before doing the slow operation by:

首先,通过以下方式启用性能分析,然后再执行缓慢的操作:

:profile start profile.log
:profile func *
:profile file *

Then you can do the slow action in Vim as usual.

然后,您可以照常在Vim中执行缓慢的操作。

After doing the slow actions, you can stop the profiling by:

执行缓慢的操作后,可以通过以下方式停止分析:

:profile pause
:wq

In the profile.log, you can check the profiling of the functions called.

在profile.log中,您可以检查所调用函数的性能分析。

If there are plugins that are very slow, the profiling results will show you the suspicious ones. You may try to disable these plugins and see whether Vim can turn to be faster or profile again.

如果有非常慢的插件,分析结果将向您显示可疑的插件。 您可以尝试禁用这些插件,然后查看Vim是否可以变得更快或再次进行配置。

The profile.log is usually quite large depending on the number of functions called. One example profile.log I got during saving a Scala source file can be found here.

profile.log通常很大,具体取决于调用的函数数。 在保存Scala源文件期间获得的一个示例profile.log 可以在这里找到

You can directly go to the summary at the end of the profile.log and check the results. The summary from the above example is as follows.

您可以直接转到profile.log末尾的摘要并检查结果。 以上示例的摘要如下。

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
    1 127.616234   0.000035  <SNR>27_BufWritePostHook()
    1 127.616184   0.000131  <SNR>27_UpdateErrors()
    1 127.615884   0.000138  <SNR>27_CacheErrors()
    1 127.586013   0.000019  16()
    1 127.585994   0.000104  15()
    1 127.585890   0.000054  SyntaxCheckers_scala_fsc_GetLocList()
    1 127.585429   0.000217  SyntasticMake()
    1   0.029151   0.000056  78()
    1   0.029048   0.028209  85()
    2   0.003059   0.000067  <SNR>50_OnCursorHold()
    2   0.002786   0.002718  <SNR>50_OnFileReadyToParse()
    1   0.001322             <SNR>37_Highlight_Matching_Pair()
    6   0.000725   0.000672  Tlist_Get_Tagname_By_Line()
    1   0.000719   0.000494  AutoTag()
    3   0.000377   0.000068  77()
    1   0.000352   0.000041  18()
    1   0.000339   0.000030  <SNR>27_ClearCache()
    5   0.000262   0.000115  24()
    1   0.000242   0.000164  74()
    1   0.000225   0.000116  <SNR>29_Tlist_Update_Current_File()

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
    1   0.029048   0.028209  85()
    2   0.002786   0.002718  <SNR>50_OnFileReadyToParse()
    1              0.001322  <SNR>37_Highlight_Matching_Pair()
    6   0.000725   0.000672  Tlist_Get_Tagname_By_Line()
    1   0.000719   0.000494  AutoTag()
    1 127.585429   0.000217  SyntasticMake()
    3              0.000202  10()
    1   0.000242   0.000164  74()
    2              0.000152  <SNR>50_AllowedToCompleteInCurrentFile()
    1 127.615884   0.000138  <SNR>27_CacheErrors()
    1 127.616184   0.000131  <SNR>27_UpdateErrors()
   15              0.000118  syntastic#util#argsescape()
    1   0.000225   0.000116  <SNR>29_Tlist_Update_Current_File()
    5   0.000262   0.000115  24()
    1 127.585994   0.000104  15()
    2   0.000124   0.000089  <SNR>27__skip_file()
    3   0.000083   0.000075  83()
    3   0.000377   0.000068  77()
    2   0.003059   0.000067  <SNR>50_OnCursorHold()
    7              0.000058  <SNR>29_Tlist_Get_File_Index()

In this example, SyntaxCheckers_scala_fsc_GetLocList() and SyntasticMake() (called by SyntaxCheckers_scala_fsc_GetLocList() if you look at the top parts of the profile.log for the function) cost more than 127 seconds. And Vim was also blocked for that long time. Actually, I had to press "Ctrl-C" to stop the operation.

在此示例中, SyntaxCheckers_scala_fsc_GetLocList()SyntasticMake() (如果您查看此功能的profile.log的顶部,则由SyntaxCheckers_scala_fsc_GetLocList()调用)花费了127秒以上。 Vim也被封锁了很长时间。 实际上,我必须按“ Ctrl-C”才能停止操作。

From the profiling results, it seems that "syntastic" plugin was trying to compile the Scala source file and find whether there were errors. Compiling Scala source file takes lots time and sbt is a better tool to do this. Hence, I disabled automatic syntactic check for Scala from syntastic by adding the line let g:syntastic_scala_checkers=[''] to my ~/.vimrc file. After this, Vim is fast again for saving Scala source files.

从分析结果来看,“ syntastic”插件似乎正在尝试编译Scala源文件并查找是否存在错误。 编译Scala源文件需要很多时间,而sbt是一个更好的工具。 因此,我通过在我的〜/ .vimrc文件中添加了let g:syntastic_scala_checkers=['']的行来禁用Syncal的Scala自动语法检查。 此后,Vim再次快速保存了Scala源文件。

翻译自: https://www.systutorials.com/profiling-vim-to-find-out-which-plugin-makes-vim-slow/

vim 插件 慢

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值