chrisbra / Recover.vim

A Plugin to show a diff, whenever recovering a buffer
http://www.vim.org/scripts/script.php?script_id=3068
247 stars 25 forks source link

Slow startup #67

Closed jonathf closed 3 years ago

jonathf commented 3 years ago

I'm a long time fan of the plugin, thanks for your cotribution.

Lately as startup has become quite slow on my machine. Any idea on what is going on here?

My nvim version info:

:version
NVIM v0.4.4
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -W
strict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURC
E -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.4.4/src -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/incl
ude
Compiled by builduser

Features: +acl +iconv +tui

init.rc file:

call plug#begin()
Plug 'chrisbra/Recover'
call plug#end()

Loging startup times with:

nvim --startup-time logfile

Content of logfile:

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

000.005  000.005: --- NVIM STARTING ---
000.238  000.233: locale set
000.428  000.191: inits 1
000.442  000.013: window checked
000.444  000.003: parsing arguments
000.483  000.039: expanding arguments
000.518  000.035: inits 2
000.904  000.387: init highlight
000.958  000.054: waiting for UI
001.723  000.765: done waiting for UI
001.751  000.028: initialized screen early for UI
002.848  001.020  001.020: sourcing /home/jonathf/.config/nvim/autoload/plug.vim
011.616  008.351  008.351: sourcing /usr/share/nvim/runtime/filetype.vim
011.772  000.047  000.047: sourcing /usr/share/nvim/runtime/ftplugin.vim
011.856  000.031  000.031: sourcing /usr/share/nvim/runtime/indent.vim
012.382  000.347  000.347: sourcing /usr/share/nvim/runtime/syntax/syncolor.vim
012.530  000.557  000.210: sourcing /usr/share/nvim/runtime/syntax/synload.vim
012.555  000.641  000.083: sourcing /usr/share/nvim/runtime/syntax/syntax.vim
012.572  010.785  000.695: sourcing /home/jonathf/.config/nvim/init.vim
012.577  000.041: sourcing vimrc file(s)
013.121  000.354  000.354: sourcing /home/jonathf/.config/nvim/plugged/Recover.vim/plugin/recover.vim
013.751  000.375  000.375: sourcing /usr/share/nvim/runtime/plugin/gzip.vim
013.796  000.009  000.009: sourcing /usr/share/nvim/runtime/plugin/health.vim
014.071  000.261  000.261: sourcing /usr/share/nvim/runtime/plugin/man.vim
014.524  000.167  000.167: sourcing /usr/share/nvim/runtime/pack/dist/opt/matchit/plugin/matchit.vim
014.558  000.466  000.298: sourcing /usr/share/nvim/runtime/plugin/matchit.vim
014.685  000.113  000.113: sourcing /usr/share/nvim/runtime/plugin/matchparen.vim
015.173  000.471  000.471: sourcing /usr/share/nvim/runtime/plugin/netrwPlugin.vim
015.460  000.105  000.105: sourcing /usr/share/nvim/runtime/autoload/remote/host.vim
015.643  000.092  000.092: sourcing /usr/share/nvim/runtime/autoload/remote/define.vim
015.701  000.387  000.190: sourcing /home/jonathf/.local/share/nvim/rplugin.vim
015.705  000.496  000.108: sourcing /usr/share/nvim/runtime/plugin/rplugin.vim
015.815  000.087  000.087: sourcing /usr/share/nvim/runtime/plugin/shada.vim
015.859  000.019  000.019: sourcing /usr/share/nvim/runtime/plugin/spellfile.vim
015.992  000.113  000.113: sourcing /usr/share/nvim/runtime/plugin/tarPlugin.vim
016.077  000.059  000.059: sourcing /usr/share/nvim/runtime/plugin/tohtml.vim
016.111  000.015  000.015: sourcing /usr/share/nvim/runtime/plugin/tutor.vim
016.254  000.126  000.126: sourcing /usr/share/nvim/runtime/plugin/zipPlugin.vim
016.259  000.720: loading plugins
016.313  000.054: loading packages
016.346  000.033: loading after plugins
016.356  000.010: inits 3
018.849  002.493: reading ShaDa
450.274  431.212  431.212: sourcing /home/jonathf/.config/nvim/plugged/Recover.vim/autoload/recover.vim
450.349  000.288: opening buffers
450.378  000.029: BufEnter autocommands
450.384  000.005: editing files in windows
450.465  000.081: VimEnter autocommands
450.469  000.004: UIEnter autocommands
450.471  000.002: before starting main loop
451.540  001.069: first screen update
451.543  000.003: --- NVIM STARTED ---

I've tested both a minimal and my full rc setup without the recover plugin, and then everything is fast again.

chrisbra commented 3 years ago

could that be a problem of the ShaDa file? can you try without such a file?

jonathf commented 3 years ago

You mean ~/.local/share/nvim/shada/main.shada?

I just tried moving it away. No effect on load time (but a new shada files was instantly created).

jonathf commented 3 years ago

I did a binary search trying to locate the problem. Landed on this commit:

  commit f545fa8cf2ef26a3989237ad180aba8113e886d3 (HEAD)
  Author: Christian Brabandt <cb@256bit.org>
  Date:   Wed Aug 22 09:57:15 2018 +0200

      Make use of swap_info() function for Vim 8.1.313

Before it the plugin is fast. After it is slow. (Yeah, I know. I hadn't updated in a while.)

chrisbra commented 3 years ago

Interesting. Does neovim have a swap_info() function?

jonathf commented 3 years ago

No. But it has the function swapinfo.

chrisbra commented 3 years ago

okay, that's what I meant.

Okay, so let's try to see if when we disable the swapinfo() function it works as fast as before. Please check the following patch:

diff --git a/autoload/recover.vim b/autoload/recover.vim
index 148108b..1f34bca 100755
--- a/autoload/recover.vim
+++ b/autoload/recover.vim
@@ -8,7 +8,7 @@
 " GetLatestVimScripts: 3068 19 :AutoInstall: recover.vim

 let s:progpath=(v:version > 704 || (v:version == 704 && has("patch234")) ? v:progpath : 'vim')
-let s:swapinfo=exists("*swapinfo")
+let s:swapinfo=0
 let s:is_linux = has("unix") && system('uname') =~? 'linux'

 fu! s:Swapname() "{{{1
jonathf commented 3 years ago

Unfortunatly no difference.

chrisbra commented 3 years ago

Hm, too bad. Can you do some profiling

E.g. start vim/nvim with a minimal config using this way:

vim --cmd ':profile start profile.log' --cmd ':profile func *' --cmd ':profile file *' -u vimrc 

and after it has start up, simply quit it :q! and then show the profile.log file please.

jonathf commented 3 years ago

profile.log

chrisbra commented 3 years ago

SCRIPT /home/jonathf/.config/nvim/plugged/Recover.vim/autoload/recover.vim Sourced 1 time Total time: 0.413317 Self time: 0.000242

count total (s) self (s) " Vim plugin for diffing when swap file was found " --------------------------------------------------------------- " Author: Christian Brabandt cb@256bit.org " Version: 0.19 " Last Change: Thu, 15 Jan 2015 21:26:55 +0100 " Script: http://www.vim.org/scripts/script.php?script_id=3068 " License: VIM License " GetLatestVimScripts: 3068 19 :AutoInstall: recover.vim

1              0.000015 let s:progpath=(v:version > 704 || (v:version == 704 && has("patch234")) ? v:progpath : 'vim')
1              0.000005 let s:swapinfo=exists("*swapinfo")
1   0.413109   0.000034 let s:is_linux = has("unix") && system('uname') =~? 'linux'

ah okay, found it. I think I have fixed that now.

jonathf commented 3 years ago

That did the trick. Thanks for the help.