Profiling vim startup returns the fact that some files are loaded N times.
nivacolors.vim
syncolor.vim
How can I fix that to load those files just one time please ?
Thank you
clock elapsed: other lines
000.000 000.000: --- VIM STARTING ---
000.000 000.000: Allocated generic buffers
001.000 001.000: locale set
003.000 002.000: GUI prepared
003.000 000.000: clipboard setup
003.000 000.000: window checked
004.000 001.000: inits 1
008.000 004.000: parsing arguments
008.000 000.000: expanding arguments
008.000 000.000: shell init
008.000 000.000: inits 2
009.000 001.000: init highlight
217.000 000.000 000.000: sourcing D:\Logiciels\Vim\vimfiles\colors\nivacolors.vim
223.000 002.000 002.000: sourcing D:\Logiciels\Vim\vim80\syntax\syncolor.vim
225.000 000.000 000.000: sourcing D:\Logiciels\Vim\vim80\syntax\syncolor.vim
226.000 007.000 005.000: sourcing D:\Logiciels\Vim\vimfiles\colors\nivacolors.vim
226.000 007.000 000.000: sourcing D:\Logiciels\Vim\vim80\syntax\synload.vim
243.000 000.000 000.000: sourcing D:\Logiciels\Vim\vimfiles\ftdetect\c.vim
244.000 000.000 000.000: sourcing D:\Logiciels\Vim\vimfiles\ftdetect\cs.vim
244.000 000.000 000.000: sourcing D:\Logiciels\Vim\vimfiles\ftdetect\ldf.vim
245.000 000.000 000.000: sourcing D:\Logiciels\Vim\vimfiles\ftdetect\log.vim
245.000 000.000 000.000: sourcing D:\Logiciels\Vim\vimfiles\ftdetect\logconfedit.vim
246.000 000.000 000.000: sourcing D:\Logiciels\Vim\vimfiles\ftdetect\py.vim
246.000 000.000 000.000: sourcing D:\Logiciels\Vim\vimfiles\ftdetect\snippets.vim
247.000 000.000 000.000: sourcing D:\Logiciels\Vim\vimfiles\ftdetect\sqllog.vim
247.000 000.000 000.000: sourcing D:\Logiciels\Vim\vimfiles\ftdetect\UltiSnips.vim
248.000 000.000 000.000: sourcing D:\Logiciels\Vim\vimfiles\ftdetect\vat.vim
248.000 000.000 000.000: sourcing D:\Logiciels\Vim\vimfiles\ftdetect\xaml.vim
249.000 000.000 000.000: sourcing D:\Logiciels\Vim\awesomeplugins\vim\awl\ftdetect\awl.vim
250.000 000.000 000.000: sourcing D:\Logiciels\Vim\awesomeplugins\vim\sonictemplate-vim\ftdetect\stpl.vim
252.000 000.000 000.000: sourcing D:\Logiciels\Vim\awesomeplugins\vim\vim-ps1\ftdetect\ps1.vim
252.000 000.000 000.000: sourcing D:\Logiciels\Vim\awesomeplugins\vim\vim-ps1\ftdetect\ps1xml.vim
253.000 000.000 000.000: sourcing D:\Logiciels\Vim\awesomeplugins\vim\vim-ps1\ftdetect\xml.vim
256.000 001.000 001.000: sourcing D:\Logiciels\Vim\vim80\lang/menu_fr_fr.latin1.vim
256.000 001.000 000.000: sourcing D:\Logiciels\Vim\vim80\lang\menu_fr.utf-8.vim
258.000 000.000 000.000: sourcing D:\Logiciels\Vim\vim80\autoload\paste.vim
294.000 040.000 039.000: sourcing D:\Logiciels\Vim\vim80/menu.vim
294.000 068.000 028.000: sourcing D:\Logiciels\Vim\vim80\filetype.vim
294.000 076.000 001.000: sourcing D:\Logiciels\Vim\vim80\syntax\syntax.vim
295.000 000.000 000.000: sourcing D:\Logiciels\Vim\vim80\syntax/nosyntax.vim
298.000 000.000 000.000: sourcing D:\Logiciels\Vim\vim80\syntax\syncolor.vim
299.000 000.000 000.000: sourcing D:\Logiciels\Vim\vim80\syntax\syncolor.vim
300.000 003.000 003.000: sourcing D:\Logiciels\Vim\vimfiles\colors\nivacolors.vim
300.000 004.000 001.000: sourcing D:\Logiciels\Vim\vim80\syntax\synload.vim
300.000 005.000 001.000: sourcing D:\Logiciels\Vim\vim80\syntax\syntax.vim
301.000 000.000 000.000: sourcing D:\Logiciels\Vim\vim80\filetype.vim
302.000 000.000 000.000: sourcing D:\Logiciels\Vim\vim80\ftplugin.vim
303.000 000.000 000.000: sourcing D:\Logiciels\Vim\vim80\indent.vim
305.000 001.000 001.000: sourcing D:\Logiciels\Vim\vim80\syntax/nosyntax.vim
307.000 000.000 000.000: sourcing D:\Logiciels\Vim\vim80\syntax\syncolor.vim
308.000 000.000 000.000: sourcing D:\Logiciels\Vim\vim80\syntax\syncolor.vim
309.000 003.000 003.000: sourcing D:\Logiciels\Vim\vimfiles\colors\nivacolors.vim
309.000 004.000 001.000: sourcing D:\Logiciels\Vim\vim80\syntax\synload.vim
309.000 005.000 000.000: sourcing D:\Logiciels\Vim\vim80\syntax\syntax.vim
310.000 300.000 214.000: sourcing $VIM\_vimrc
2017/5/26 Fri 22:36:40 UTC+9 Ken Takata wrote:
> > 096.000 047.000 044.000: sourcing D:\Logiciels\Vim\vim80/menu.vim
> > 096.000 072.000 025.000: sourcing D:\Logiciels\Vim\vim80\filetype.vim
>
> menu.vim uses `globpath()` to search some kind of files under the
runtimepath.
> If you search `globpath` in menu.vim, you may find the following lines:
>
> let s:n = globpath(&runtimepath, "colors/*.vim")
> let s:n = globpath(&runtimepath, "keymap/*.vim")
> let s = globpath(&rtp, "spell/*." . enc . ".spl")
> let s:n = globpath(&runtimepath, "compiler/*.vim")
>
> Color schemes, keymaps, spell files and compiler plugins are searched when
> menu.vim is loaded.
> This is why it takes long time to be loaded.
>
> Unlike those items, file types are not listed automatically. If a user
> selects "Syntax" -> "Show File Types in Menu", they will be listed.
> If we use a similar way for color schemes etc., the startup time would be
> reduced.
I wrote a patch for reduce the loading the of menu.vim by skip using
globpath().
Instead of searching colors/*.vim and other files, the following menuitems are
added in the menu:
Edit > Show Color Schemes in Menu
Edit > Show Keymaps in Menu
Tools > Show Compiler Settings in Menu
If these menuitems are selected, all available colorschemes etc. are shown
in the menu. If a user want to load them at startup, the following line
can be added in .vimrc:
:let do_globpath_menus = 1
(This is similar to `:let do_syntax_sel_menu = 1`.)
In my environment, the loading time of menu.vim is:
Without this patch: 30 - 50 ms
Skip using globpath: 15 - 20 ms
Regards,
Ken Takata
How about this additional patch, then?
https://bitbucket.org/k_takata/vim-ktakata-mq/src/938cf6a5e03ef2ccbc131ca2a3eb5bae364beb7b/improve-loading-menu.vim-cursorhold.patch?at=default&fileviewer=file-view-default
This uses CursorHold to load the menuitems when idle.
Regards,
Ken Takata
I have updated the patches:
https://bitbucket.org/k_takata/vim-ktakata-mq/src/c58b17bb22261436910d77dcda76409edd962ad5/improve-loading-menu.vim.patch?at=default&fileviewer=file-view-default
Changes are:
* Merge the two patches into one.
* Update the document.
* Rename the global variable `do_globpath_menus` to `do_lazyload_menus`.
I'm still wondering what is the best name for this variable.
* Remove `has('win16')`. Not needed anymore.
* Add <silent> to the "Show File Types in Menu" item. Showing the command
of this item is not so useful.
Regards,
Ken Takata
2017/10/25 Wed 21:28:50 UTC+9 Christian Brabandt wrote:
> Hi Ken,
> I briefly looked at your patch and have some feedback.
>
> On Mi, 25 Okt 2017, Ken Takata wrote:
>
> > Changes are:
> > * Merge the two patches into one.
> > * Update the document.
> > * Rename the global variable `do_globpath_menus` to `do_lazyload_menus`.
> > I'm still wondering what is the best name for this variable.
> > * Remove `has('win16')`. Not needed anymore.
> > * Add <silent> to the "Show File Types in Menu" item. Showing the command
> > of this item is not so useful.
>
> +If you want to have all these items already present at startup, add: >
> + :let do_lazyload_menus = 1
>
> I think this variable should either be called `do_no_lazyload_menus` or
> the value should be 0, since by default the menus will be lazy loaded.
Okay, I changed it to `do_no_lazyload_menus`:
https://bitbucket.org/k_takata/vim-ktakata-mq/src/cda66cbfc90b98a5ca6c16229ee129fd448c1bad/improve-loading-menu.vim.patch?fileviewer=file-view-default
Actually, menu.vim only checks the existence of the global variable, the value
is not checked. This is the same as other variable in menu.vim.
> + let n = globpath(&runtimepath, "colors/*.vim")
>
> I think that should be
>
> + let n = globpath(&runtimepath, "colors/*.vim", 1, 1)
>
> So you have a list available already and don't need to split later on
> manually and you probably do want to ignore the suffixes and wildignore
> options, if only the user having set them to bad values.
>
> The same holds for the keymap and compiler runtime files.
It makes the code simpler. Updated.
> + augroup SetupLazyloadMenus
> + au!
> + au CursorHold,CursorHoldI * call <SID>SetupLazyloadMenus() | au! SetupLazyloadMenus
> + augroup END
>
> Is this actually a good idea to delete the augroup from within itself?
Deleting autocommands in the group is a usual usage. The similar usage can be
found in `augroup LoadBufferMenu` in menu.vim. Moreover, just using `au!`
in an augroup is a normal usage. Deleting an autogroup within itself by
`augroup!` doesn't work in contrast. It causes W19 or E936.
Actually, I want to delete the group here...
> BTW: there are many runtime file variables. Perhaps we should start to
> document internal runtime file variables in a help file at a central
> place.
>
> Also I am starting to wonder, whether it would make sense to start using
> a common prefix, so that the names are more consistent and less likely
> to clash with user variables, e.g. something like
> vim_ftplugin_undo
> vim_indent_undo
> vim_menu_init_immediate
Regards,
Ken Takata