goolord / alpha-nvim

a lua powered greeter like vim-startify / dashboard-nvim
MIT License
1.92k stars 113 forks source link

slow startuptime on old cpu #25

Closed siduck closed 2 years ago

siduck commented 3 years ago

hi! I had used dashboard-nvim before and it was quite fast and written in vimscript . I have a low end machine with pentium cpu so the startuptime matters for me!

alpha :

image

dashboard-nvim :

image

siduck commented 3 years ago

tested with https://github.com/norcalli/profiler.nvim

goolord commented 3 years ago

startify does a lot more than dashboard, this is comparing apples to oranges. most of the time is spent doing I/O for the most recently opened files sections.

i haven't compared performance between alpha-nvim's dashboard theme and dashboard-nvim, but between the startify theme and vim-startify drawing the screen is slightly faster in alpha

goolord commented 3 years ago

comparing the dashboard theme with dasbhoard.nvim:

Config for alpha-nvim took 0.277057ms
...
VimEnter autocommand   7.19 ms
VimEnter autocommand   8.22
dashboard.vim          0.23ms

measured with nvim --startuptime and PackerProfile

on my machine they are comparable, sourcing alpha is 0.05ms slower and drawing is ~1 ms faster. but i'm also using https://github.com/lewis6991/impatient.nvim

i'll see what i can do about shaving more time off loading alpha, but i've already looked in many corners for optimizations i could make.

goolord commented 3 years ago

i think your profiling is not measuring sourcing the dashboard.nvim vimscript, actually. that seems like it's only profiling how long it takes to require your config, which presumably just sets some global variables

siduck commented 3 years ago

i think your profiling is not measuring sourcing the dashboard.nvim vimscript, actually. that seems like it's only profiling how long it takes to require your config, which presumably just sets some global variables

you were right, I tried --startuptime and dashboard's startuptime :

image

But I dont see alpha if the profiling done with --startuptime

goolord commented 3 years ago

yes, vim --startuptime doesn't measure lua plugins. and profiling your lua plugins will not measure the time to source vim plugins. you have to use 2 profilers, one for lua and one for vimL

siduck commented 3 years ago

But yea one thing Ive seen is that the overall startuptime is less when dashboard-nvim is used (used --startuptime)

image

goolord commented 3 years ago

what does your alpha config look like

siduck commented 3 years ago

what does your alpha config look like

its the default one

siduck commented 3 years ago
     require("alpha").setup(require("alpha.themes.dashboard").opts)
goolord commented 3 years ago

ok, there is a lot of variance here, so it's hard to tell exactly what's happening just by looking at your --startuptime output. i will investigate this more later

goolord commented 3 years ago

ok, with no impatient.nvim even, this plugin is decisively faster on my machine

dashboard.nvim

(no config)

`nvim --startuptime` 100 samples ``` startup: 116.9 event time percent plot packer_compiled.lua 36.90 31.55 ██████████████████████████ BufEnter autocommand 11.79 10.08 ████████▎ filetype.vim 8.37 7.16 █████▉ VimEnter autocommand 8.05 6.88 █████▋ init.lua 6.97 5.96 ████▉ cmp-tabnine.lua 5.42 4.63 ███▉ first screen update 4.54 3.89 ███▎ parsing arguments 4.06 3.47 ██▉ reading ShaDa 3.73 3.19 ██▋ loading plugins 3.67 3.14 ██▋ vsnip.vim 3.20 2.73 ██▎ session.vim 2.98 2.55 ██▏ TabularMaps.vim 1.89 1.62 █▍ loading packages 1.86 1.59 █▍ gruvbox8.vim 1.67 1.43 █▏ snippet.vim 1.55 1.32 █▏ cmp_path.lua 1.27 1.09 ▉ fugitive.vim 1.21 1.03 ▉ cmp_nvim_lsp.lua 1.19 1.02 ▉ cmp_buffer.lua 1.17 1.00 ▉ loading after plugin 0.98 0.83 ▋ opening buffers 0.84 0.72 ▋ Position.vim 0.78 0.67 ▌ indent_blankline.vim 0.75 0.64 ▌ cmp_calc.lua 0.72 0.62 ▌ matchit.vim 0.72 0.62 ▌ vsnip_integ.vim 0.68 0.58 ▌ cmp_emoji.lua 0.65 0.55 ▌ fzf.vim 0.63 0.54 ▌ cmp_vsnip.vim 0.60 0.51 ▍ init highlight 0.57 0.48 ▍ done waiting for UI 0.52 0.44 ▍ vsnip.vim 0.33 0.29 ▎ inits 1 0.33 0.29 ▎ locale set 0.30 0.26 ▎ NvimTree.vim 0.30 0.26 ▎ vsnip.vim 0.29 0.25 ▎ syntax.vim 0.24 0.21 ▏ matchit.vim 0.23 0.20 ▏ dashboard.vim 0.22 0.19 ▏ expanding arguments 0.21 0.18 ▏ tabular.vim 0.17 0.15 ▏ Tabular.vim 0.16 0.14 ▏ matchparen.vim 0.16 0.13 ▏ rplugin.vim 0.14 0.12 ▏ dashboard.vim 0.13 0.11 ▏ telescope.vim 0.12 0.10 ▏ Diff.vim 0.11 0.10 ▏ section.vim 0.11 0.09 ▏ TextEdit.vim 0.11 0.09 ▏ trouble.vim 0.10 0.09 ▏ tree.vim 0.10 0.09 ▏ Buffer.vim 0.10 0.08 ▏ init default autocom 0.10 0.08 ▏ cmp.lua 0.09 0.08 ▏ synload.vim 0.09 0.08 ▏ cfilter.vim 0.08 0.07 vsnip_integ.vim 0.07 0.06 sourcing vimrc file( 0.07 0.06 dashboard.vim 0.06 0.05 sysinit.vim 0.05 0.04 Text.vim 0.05 0.04 header.vim 0.05 0.04 Option.vim 0.04 0.04 detection.vim 0.04 0.03 ftplugin.vim 0.04 0.03 toml.vim 0.04 0.03 indent.vim 0.04 0.03 initialized screen e 0.03 0.03 toggleterm.vim 0.03 0.03 plenary.vim 0.03 0.03 init default mapping 0.03 0.03 meson.vim 0.03 0.03 nvim-web-devicons.vi 0.03 0.03 inits 2 0.03 0.02 nix.vim 0.02 0.02 utils.vim 0.02 0.02 idris2.vim 0.02 0.02 _vsnip.vim 0.02 0.02 inits 3 0.02 0.02 integration.vim 0.02 0.02 netrwPlugin.vim 0.02 0.02 executing command ar 0.02 0.02 gzip.vim 0.02 0.01 archlinux.vim 0.02 0.01 zipPlugin.vim 0.02 0.01 tarPlugin.vim 0.02 0.01 indent_blankline.vim 0.02 0.01 cfilter.vim 0.01 0.01 fugitive.vim 0.01 0.01 nix.vim 0.01 0.01 tohtml.vim 0.01 0.01 coq.vim 0.01 0.01 window checked 0.01 0.01 health.vim 0.01 0.01 lidris2.vim 0.01 0.01 spellfile.vim 0.01 0.01 dashboard.vim 0.01 0.01 man.vim 0.01 0.01 --- NVIM STARTING -- 0.01 0.01 rplugin.vim 0.01 0.01 shada.vim 0.01 0.01 tutor.vim 0.01 0.01 editing files in win 0.01 0.01 UIEnter autocommands 0.00 0.00 --- NVIM STARTED --- 0.00 0.00 waiting for UI 0.00 0.00 before starting main 0.00 0.00 ```

alpha

    use {
        "~/Dev/alpha-nvim",
        config = function () require("alpha").setup(require("alpha.themes.dashboard").opts) end
    }
`nvim --startuptime` 100 samples ``` startup: 111.7 event time percent plot packer_compiled.lua 37.37 33.45 ██████████████████████████ BufEnter autocommand 11.82 10.58 ████████▎ filetype.vim 7.69 6.88 █████▍ VimEnter autocommand 7.16 6.41 █████ init.lua 6.04 5.40 ████▎ cmp-tabnine.lua 5.65 5.06 ███▉ first screen update 3.82 3.42 ██▋ reading ShaDa 3.72 3.33 ██▋ parsing arguments 3.67 3.29 ██▌ loading plugins 3.49 3.12 ██▍ vsnip.vim 2.52 2.26 █▊ session.vim 2.30 2.06 █▋ TabularMaps.vim 1.89 1.69 █▍ loading packages 1.81 1.62 █▎ gruvbox8.vim 1.68 1.50 █▏ cmp_nvim_lsp.lua 1.30 1.16 ▉ fugitive.vim 1.21 1.08 ▉ cmp_path.lua 1.04 0.93 ▊ loading after plugin 0.97 0.87 ▋ cmp_buffer.lua 0.87 0.78 ▋ snippet.vim 0.85 0.76 ▋ indent_blankline.vim 0.83 0.75 ▋ cmp_calc.lua 0.73 0.66 ▌ matchit.vim 0.70 0.63 ▌ vsnip_integ.vim 0.68 0.61 ▌ cmp_vsnip.vim 0.65 0.58 ▌ cmp_emoji.lua 0.64 0.57 ▌ opening buffers 0.62 0.55 ▍ fzf.vim 0.60 0.54 ▍ init highlight 0.50 0.45 ▍ done waiting for UI 0.46 0.41 ▍ vsnip.vim 0.34 0.30 ▎ NvimTree.vim 0.31 0.28 ▎ inits 1 0.31 0.28 ▎ locale set 0.29 0.26 ▎ vsnip.vim 0.26 0.23 ▏ syntax.vim 0.23 0.21 ▏ matchit.vim 0.22 0.20 ▏ expanding arguments 0.19 0.17 ▏ tabular.vim 0.17 0.15 ▏ Tabular.vim 0.16 0.14 ▏ matchparen.vim 0.15 0.13 ▏ rplugin.vim 0.14 0.12 ▏ telescope.vim 0.12 0.11 ▏ Diff.vim 0.11 0.10 ▏ tree.vim 0.11 0.09 ▏ TextEdit.vim 0.10 0.09 ▏ trouble.vim 0.10 0.09 ▏ cmp.lua 0.10 0.09 ▏ Buffer.vim 0.10 0.09 ▏ Position.vim 0.09 0.08 synload.vim 0.09 0.08 init default autocom 0.08 0.08 cfilter.vim 0.07 0.06 vsnip_integ.vim 0.07 0.06 sourcing vimrc file( 0.06 0.05 Text.vim 0.05 0.05 Option.vim 0.04 0.04 sysinit.vim 0.04 0.04 detection.vim 0.04 0.04 ftplugin.vim 0.04 0.03 toml.vim 0.04 0.03 indent.vim 0.03 0.03 toggleterm.vim 0.03 0.03 plenary.vim 0.03 0.03 initialized screen e 0.03 0.03 nvim-web-devicons.vi 0.03 0.03 meson.vim 0.03 0.03 init default mapping 0.03 0.02 inits 2 0.02 0.02 nix.vim 0.02 0.02 _vsnip.vim 0.02 0.02 executing command ar 0.02 0.02 idris2.vim 0.02 0.02 integration.vim 0.02 0.02 inits 3 0.02 0.02 netrwPlugin.vim 0.02 0.02 gzip.vim 0.02 0.01 indent_blankline.vim 0.02 0.01 zipPlugin.vim 0.02 0.01 tarPlugin.vim 0.02 0.01 archlinux.vim 0.01 0.01 coq.vim 0.01 0.01 cfilter.vim 0.01 0.01 tohtml.vim 0.01 0.01 fugitive.vim 0.01 0.01 nix.vim 0.01 0.01 window checked 0.01 0.01 health.vim 0.01 0.01 lidris2.vim 0.01 0.01 spellfile.vim 0.01 0.01 --- NVIM STARTING -- 0.01 0.01 rplugin.vim 0.01 0.01 man.vim 0.01 0.01 shada.vim 0.01 0.01 tutor.vim 0.01 0.01 editing files in win 0.01 0.01 UIEnter autocommands 0.01 0.00 --- NVIM STARTED --- 0.00 0.00 before starting main 0.00 0.00 waiting for UI 0.00 0.00 ```
siduck commented 3 years ago

the inbuild --startuptime doesnt show the bar graph! how did you get it :O

goolord commented 3 years ago

https://github.com/dstein64/vim-startuptime ! it's a cool plugin.

goolord commented 3 years ago

i think there may be something else going on here, like maybe require in nvim is slow on a mechanical drive, or maybe luajit generates worse machine code for a pentium than vimL's interpreter. mysterious

goolord commented 3 years ago

profiling using https://luarocks.org/modules/luarocks/luaprofiler didn't turn up anything suspicious either. most of the expensive functions have to do with drawing (which would fall under VimEnter)

goolord commented 3 years ago

ok, i think i will write a minimal vimrc and make a branch with some debugging profiling stuff and have you run it later, if you're willing

siduck commented 3 years ago

can you try using nvim's built in startuptime flag? vim-staruptime keeps showing different startuptimes every time i run :St

try nvim --startuptime dashboard

nvim --startuptime alpha

siduck commented 3 years ago

i think there may be something else going on here, like maybe require in nvim is slow on a mechanical drive, or maybe luajit generates worse machine code for a pentium than vimL's interpreter. mysterious

probably , I have a low end pentium machine with a hdd , so the startuptime difference is usally noticeable.

goolord commented 3 years ago

vim-staruptime just calls nvim --startuptime internally, if you run nvim --startuptime prof you will see that the startup time is different every time. that's why the plugin allows you to average the startup time over a number of samples. the results are more or less the same for me when i run it from the command line

tangentially: i don't actually know why the startup time is different every time, if i had to guess it's just branch prediction, cache misses, maybe sometimes you just get unlucky and the scheduler doesn't allocate resources to vim, idk. another mystery

goolord commented 3 years ago

@siduck76 ok i figured out how to do a minimal vimrc for this. i have incidentally been pushing a bunch of minor performance improvements. i'm curious if any of them fixed the startup time issues on your machine

siduck commented 3 years ago

@goolord yes it reduced 10ms

image

goolord commented 2 years ago

@siduck there is a new option which might improve things for you https://github.com/goolord/alpha-nvim/commit/7ceb62ed560d7989585732728240db3ebffc5692

lmk if you get the time to test it

goolord commented 2 years ago

also the new should_skip_alpha heuristics are a little more accurate so plugins like https://github.com/dstein64/vim-startuptime will more faithfully represent the real world, which could be helpful since it can collect multiple samples

siduck commented 2 years ago

@goolord its fixed now