Open jyscao opened 5 years ago
I just created PR for a workaround to this issue.
Once you merge that PR, I will just add lua_foldmethod = "manual"
in my SpaceVim's init.toml
.
this should be a layer option for lang#lua layer
layer option added to lang#lua as advised (SpaceVim PR #3123)
As previously mentioned in the chat some days ago, enabling the Lua layer, which includes this plugin makes working with Lua files very slow. Originally, I'd thought it was only caused by the inherent slow nature of using
expr
as thefoldmethod
, since it calls the function for every single line. However, after some more digging, it appears the functionlua#fold#foldlevel(linenum)
used to calculate the fold levels also contributes a great deal to the slowness.I've profiled this again using the same file from before (~8kb, and now down to 306 lines total), to make sure the slowness indeed is related to the function used for
foldexpr
. First using the plugin as is, then by removing all the patterns (ex.do
,function
,end
, etc.) used to check for folds. See results below.Results using the plugin as provided:
Results with the local variable
patterns
in functionfold_iter
fromlua/luavi.lua
set to{}
:So as we can see, calling the
foldexpr
function 2x for every line of any given.lua
file is definitely problematic in itself, since even after removing all the fold checking patterns, it still takes 6+ seconds to complete. But checking against all the patterns infold_iter
causes the delay to become dramatically worse, requiring 1.5min before the buffer is ready for use.Before both causes of this slowness are fixed, I think it best to not use
expr
as thefoldmethod
for the Lua layer.