habamax / vim-asciidoctor

Asciidoctor plugin for Vim
MIT License
181 stars 16 forks source link

folding performance #84

Closed tonyspiff closed 3 years ago

tonyspiff commented 3 years ago

I run vim-easy-align to help keep my ever growing tables neat and this have been taking longer and longer. I finally had the time to do some profiling and at first glance the issue is related the fold function.

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
26404  55.274132             AsciidoctorFold()
    1  54.229878   0.000054  easy_align#align()
    1  54.229824   0.000108  <SNR>71_align()
    1  53.400168   0.227731  <SNR>71_update_lines()

My relevant global settings are:

set nofoldenable
let g:asciidoctor_syntax_conceal=1
let g:asciidoctor_folding = 1

Disabling g:asciidoctor_folding solves the performance issue. As you can notice I have nofoldenable on my startup and that doesn't help (probably AsciidoctorFold should check for that too).

NVIM v0.4.4
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/tmp/neovim-20200808-89283-1us0ytm/neovim-0.4.4/build/config -I/tmp/neovim-20200808-89283-1us0ytm/neovim-0.4.4/src -I/usr/local/include -I/tmp/neovim-20200808-89283-1us0ytm/neovim-0.4.4/deps-build/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -I/usr/local/opt/gettext/include -I/tmp/neovim-20200808-89283-1us0ytm/neovim-0.4.4/build/src/nvim/auto -I/tmp/neovim-20200808-89283-1us0ytm/neovim-0.4.4/build/include
Compiled by brew@Catalina
habamax commented 3 years ago

Folding based on expr is generally very slow in vim.

Note that 'foldenable' only makes all folds folded/unfolded. For that folds have to be detected first, which foldmethod and foldexpr are for. And they are turned on or off for asciidoctor filetype with g:asciidoctor_folding.

PS, there is a plugin that makes folds usable https://github.com/Konfekt/FastFold

tonyspiff commented 3 years ago
'foldenable' 'fen'  boolean (default on)
            local to window
    When off, all folds are open.  This option can be used to quickly
    switch between showing all text unfolded and viewing the text with
    folds (including manually opened or closed folds).  It can be toggled
    with the |zi| command.  The 'foldcolumn' will remain blank when
    'foldenable' is off.
    This option is set by commands that create a new fold or close a fold.
    See |folding|.

If foldenable is off and "all folds are open" - why would a process spend time in a function called AsciidoctorFold? What does it have to do if folding is disabled and all folds are open? 🤔

Edit: for future travelers, I fixed my particular issue with let g:easy_align_bypass_fold = 1

habamax commented 3 years ago

Folds are open, but they have to be found first. Vim runs foldexpr if foldmethod is expr. You can try to use OptionSet autocommand to set foldexpr and foldmethod depending on foldenable (didn't test it):

func! AdocFoldEnable()
    if &filetype != 'asciidoctor'
        return
    endif

    if &foldenable
        set foldmethod=expr
    else
        set foldmethod=manual
    endif
endfunc

augroup FoldEnable | au!
    au OptionSet foldenable call AdocFoldEnable()
augroup END