rktjmp / lush.nvim

Create Neovim themes with real-time feedback, export anywhere.
MIT License
1.4k stars 46 forks source link

slow startup time #127

Closed cipherlogs closed 1 year ago

cipherlogs commented 1 year ago

Not sure what's causing Lush to make my nvim seconds slow at startup time. any idea on how I can troubleshoot this issue ? Thanks.

EDIT: My problem is that I forgot " set shellcmdflag=-ic on Usually I turn it off when I don't need it.

anyway I hope this would help anyone who would come across the same issue.

always try to first run your editor without your vimrc, to test if the problem is coming from the rc itself

nvim -u "NONE"

rktjmp commented 1 year ago

Does it occur if you change your theme? Does it occur if you load lush but dont load a lush theme? What theme are you loading? What version of neovim are you running? What does nvim --startuptime file.log produce?

My files are bytecode-cached by hotpot so there's some time skipped reading and intepreting the lua files, but the actual cpu time to do anything lush related should be about the same. Lush is a couple of ms total for me on a decade old i5.

total elapsed  specific
ms             ms 
025.638        000.013  000.013: require('lush.math')
025.653        000.012  000.012: require('lush.vivid.rgb.convert')
025.655        000.044  000.019: require('lush.vivid.hsl.convert')
025.700        000.044  000.044: require('lush.vivid.hsl_like')
025.702        000.114  000.026: require('lush.vivid.hsl.type')
025.797        000.044  000.044: require('lush.vivid.hsluv.lib')
025.801        000.076  000.032: require('lush.vivid.hsluv.convert')
025.803        000.099  000.023: require('lush.vivid.hsluv.type')
025.809        000.248  000.035: require('lush')
026.853        000.144  000.144: require('lush.errors')
026.868        000.222  000.078: require('lush.parser')
029.658        000.026  000.026: require('lush.compiler')
048.331        000.038  000.038: sourcing /home/soup/.local/share/nvim/site/pack/manual/start/lush.nvim/plugin/lush.vim
cipherlogs commented 1 year ago

@rktjmp I did a couple of tests and this is what I found

when I use nvim 0.9.0 with lush the startup is about 3 seconds slower I'm using zenbones theme

below is the startup file log and I guess everything looks fine


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

000.017  000.017: --- NVIM STARTING ---
000.136  000.118: event init
000.290  000.154: early init
000.361  000.071: locale set
000.425  000.063: init first window
000.898  000.473: inits 1
000.923  000.026: window checked
000.929  000.005: parsing arguments
001.747  000.070  000.070: require('vim.shared')
001.961  000.072  000.072: require('vim._meta')
001.967  000.212  000.140: require('vim._editor')
001.971  000.365  000.083: require('vim._init_packages')
001.976  000.682: init lua interpreter
002.091  000.115: expanding arguments
002.141  000.050: inits 2
002.641  000.500: init highlight
002.644  000.004: waiting for UI
002.891  000.246: done waiting for UI
002.902  000.012: clear screen
003.134  000.232: init default mappings & autocommands
003.865  000.088  000.088: sourcing /usr/share/nvim/runtime/ftplugin.vim
003.970  000.050  000.050: sourcing /usr/share/nvim/runtime/indent.vim
004.049  000.018  000.018: sourcing /usr/share/nvim/archlinux.vim
004.057  000.053  000.034: sourcing /etc/xdg/nvim/sysinit.vim
007.223  002.546  002.546: sourcing /home/cipherlogs/.local/share/nvim/site/autoload/plug.vim
012.233  000.022  000.022: sourcing /home/cipherlogs/.local/share/nvim/plugged/vim-javascript/ftdetect/flow.vim
012.318  000.056  000.056: sourcing /home/cipherlogs/.local/share/nvim/plugged/vim-javascript/ftdetect/javascript.vim
012.404  000.017  000.017: sourcing /home/cipherlogs/.local/share/nvim/plugged/vim-solidity/ftdetect/solidity.vim
012.496  000.031  000.031: sourcing /home/cipherlogs/.local/share/nvim/plugged/haskell-vim/ftdetect/haskell.vim
012.742  000.018  000.018: sourcing /usr/share/vim/vimfiles/ftdetect/PKGBUILD.vim
012.782  000.016  000.016: sourcing /usr/share/vim/vimfiles/ftdetect/SRCINFO.vim
012.833  000.027  000.027: sourcing /usr/share/vim/vimfiles/ftdetect/conkyrc.vim
013.156  001.221  001.035: sourcing /usr/share/nvim/runtime/filetype.lua
013.345  000.021  000.021: sourcing /usr/share/nvim/runtime/ftplugin.vim
013.496  000.015  000.015: sourcing /usr/share/nvim/runtime/indent.vim
013.881  000.147  000.147: sourcing /usr/share/nvim/runtime/syntax/synload.vim
014.032  000.458  000.311: sourcing /usr/share/nvim/runtime/syntax/syntax.vim
014.239  000.093  000.093: sourcing /usr/share/nvim/runtime/syntax/nosyntax.vim
014.495  000.128  000.128: sourcing /usr/share/nvim/runtime/syntax/synload.vim
014.622  000.536  000.316: sourcing /usr/share/nvim/runtime/syntax/syntax.vim
014.934  000.113  000.113: sourcing /usr/share/nvim/runtime/filetype.lua
015.113  000.018  000.018: sourcing /usr/share/nvim/runtime/ftplugin.vim
015.257  000.014  000.014: sourcing /usr/share/nvim/runtime/indent.vim
016.018  000.022  000.022: sourcing /home/cipherlogs/.local/share/nvim/plugged/zenbones.nvim/autoload/bones.vim
016.355  000.289  000.289: require('zenbones.util')
016.869  000.048  000.048: require('lush.math')
017.033  000.156  000.156: require('lush.vivid.rgb.convert')
017.040  000.422  000.218: require('lush.vivid.hsl.convert')
017.592  000.547  000.547: require('lush.vivid.hsl_like')
017.599  001.034  000.064: require('lush.vivid.hsl.type')
018.700  000.975  000.975: require('lush.vivid.hsluv.lib')
018.713  001.047  000.072: require('lush.vivid.hsluv.convert')
018.720  001.116  000.069: require('lush.vivid.hsluv.type')
018.733  002.368  000.219: require('lush')
018.969  000.121  000.121: require('zenbones.specs')
020.634  001.655  001.655: require('tokyobones.palette')
021.553  000.890  000.890: require('zenbones.specs.dark')
022.588  000.319  000.319: require('lush.errors')
022.611  001.029  000.710: require('lush.parser')
030.209  011.472  007.776: require('tokyobones')
030.411  000.190  000.190: require('lush.compiler')
035.422  000.139  000.139: require('zenbones.term')
035.547  019.665  005.185: sourcing /home/cipherlogs/.local/share/nvim/plugged/zenbones.nvim/colors/tokyobones.vim
035.891  031.802  007.195: sourcing /home/cipherlogs/.config/nvim/init.vim
035.900  000.773: sourcing vimrc file(s)
036.476  000.169  000.169: sourcing /home/cipherlogs/.local/share/nvim/plugged/vim-highlightedyank/plugin/highlightedyank.vim
036.769  000.050  000.050: sourcing /home/cipherlogs/.local/share/nvim/plugged/tcomment_vim/autoload/tcomment/deprecated.vim
040.659  004.050  004.000: sourcing /home/cipherlogs/.local/share/nvim/plugged/tcomment_vim/plugin/tcomment.vim
041.554  000.685  000.685: sourcing /home/cipherlogs/.local/share/nvim/plugged/vim-surround/plugin/surround.vim
043.627  001.938  001.938: sourcing /home/cipherlogs/.local/share/nvim/plugged/emmet-vim/plugin/emmet.vim
044.388  000.627  000.627: sourcing /home/cipherlogs/.local/share/nvim/plugged/auto-pairs/plugin/auto-pairs.vim
044.580  000.064  000.064: sourcing /home/cipherlogs/.local/share/nvim/plugged/lush.nvim/plugin/lush.vim
044.787  000.051  000.051: sourcing /home/cipherlogs/.local/share/nvim/plugged/vim-be-good/plugin/vim-be-good.vim
045.742  000.317  000.317: sourcing /usr/share/nvim/runtime/plugin/gzip.vim
045.791  000.016  000.016: sourcing /usr/share/nvim/runtime/plugin/health.vim
046.696  000.342  000.342: sourcing /usr/share/nvim/runtime/pack/dist/opt/matchit/plugin/matchit.vim
046.870  001.052  000.710: sourcing /usr/share/nvim/runtime/plugin/matchit.vim
047.203  000.305  000.305: sourcing /usr/share/nvim/runtime/plugin/matchparen.vim
047.876  000.641  000.641: sourcing /usr/share/nvim/runtime/plugin/netrwPlugin.vim
048.286  000.337  000.337: sourcing /usr/share/nvim/runtime/plugin/rplugin.vim
048.441  000.109  000.109: sourcing /usr/share/nvim/runtime/plugin/shada.vim
048.522  000.038  000.038: sourcing /usr/share/nvim/runtime/plugin/spellfile.vim
048.753  000.196  000.196: sourcing /usr/share/nvim/runtime/plugin/tarPlugin.vim
048.971  000.162  000.162: sourcing /usr/share/nvim/runtime/plugin/tohtml.vim
049.036  000.028  000.028: sourcing /usr/share/nvim/runtime/plugin/tutor.vim
049.340  000.270  000.270: sourcing /usr/share/nvim/runtime/plugin/zipPlugin.vim
050.597  001.069  001.069: sourcing /usr/share/vim/vimfiles/plugin/fzf.vim
051.832  000.109  000.109: sourcing /usr/share/nvim/runtime/plugin/editorconfig.lua
051.993  000.118  000.118: sourcing /usr/share/nvim/runtime/plugin/man.lua
052.105  000.076  000.076: sourcing /usr/share/nvim/runtime/plugin/nvim.lua
052.201  003.874: loading rtp plugins
052.424  000.222: loading packages
053.218  000.794: loading after plugins
053.241  000.023: inits 3
057.896  004.655: reading ShaDa
058.233  000.337: opening buffers
059.992  001.759: BufEnter autocommands
059.999  000.007: editing files in windows
060.131  000.132: VimEnter autocommands
060.136  000.005: UIEnter autocommands
723.764  663.458  663.458: sourcing /usr/share/nvim/runtime/autoload/provider/clipboard.vim
723.800  000.207: before starting main loop
724.161  000.361: first screen update
724.166  000.005: --- NVIM STARTED ---

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

000.016  000.016: --- NVIM STARTING ---
000.133  000.117: event init
000.272  000.139: early init
000.345  000.074: locale set
000.407  000.062: init first window
000.891  000.484: inits 1
000.905  000.014: window checked
000.911  000.006: parsing arguments
001.742  000.146  000.146: require('vim.shared')
001.953  000.075  000.075: require('vim._meta')
001.958  000.209  000.133: require('vim._editor')
001.963  000.414  000.060: require('vim._init_packages')
001.968  000.643: init lua interpreter
002.984  001.016: expanding arguments
003.057  000.073: inits 2
003.570  000.513: init highlight
rktjmp commented 1 year ago

using vim 9.0.1420, everything loads faster (lush included) ... no problems with vim

Lush shouldn't work at all in vim. Can you reproduce the effect with a different colorscheme? And a different lush colorscheme?

cipherlogs commented 1 year ago

@rktjmp vim is using the same initrc file that I'm using with nvim. and everything works fine. when I open vim I guess compat mode is enabled by default so lush won't be called. when I try to do the same in nvim let g:theme_compat = 1, I feel like it doesn't have an effect at all.

what's even weird is when I uninstall lush, then I open nvim I get the lua error that lush isn't found, so I add let g:xxx_compat = 1 to my nvim rc.

the result is that the error disappears however, the startup is still slow ??

Also I disabled lush colorscheme and lush and used something else, nvim works perfectly fast in this situation.

rktjmp commented 1 year ago

Not sure. If you can't create a reproduction I can't really help you and with out other reports it's hard to say it's actually Lush.

You can try logging some timing around these functions which do the bulk of the work:

https://github.com/rktjmp/lush.nvim/blob/fb148c0082488ba048f681792c4044e3229fd1a6/lua/lush.lua#L29

https://github.com/rktjmp/lush.nvim/blob/fb148c0082488ba048f681792c4044e3229fd1a6/lua/lush/compiler.lua#L88

https://github.com/rktjmp/lush.nvim/blob/fb148c0082488ba048f681792c4044e3229fd1a6/lua/lush/parser.lua#L452

If those aren't taking seconds to run then you should look elsewhere in your config I think.

cipherlogs commented 1 year ago

@rktjmp

for lush.lua it takes 0.03 sec for compiler.lua it takes 2.9 e-06 sec for parser.lua

is it normal for parser.lua to be called 3 times ? why is it printing 3 times to the console?

other than that all numbers are pretty small.

rktjmp commented 1 year ago

zenbones is comprised of a few themes that extend each other I think, so the parser will be called once for each.

cipherlogs commented 1 year ago

Finally I had some free time to diagnose the problem properly, please read the updated issue section.