Skip to content

Call the quickfixtextfunc function for multiple entries#6234

Closed
yegappan wants to merge 1 commit intovim:masterfrom
yegappan:qftf
Closed

Call the quickfixtextfunc function for multiple entries#6234
yegappan wants to merge 1 commit intovim:masterfrom
yegappan:qftf

Conversation

@yegappan
Copy link
Member

To reduce the cost of calling a VimScript function for every quickfix list entry,
call the function for multiple entries.

@codecov
Copy link

codecov bot commented Jun 11, 2020

Codecov Report

Merging #6234 into master will decrease coverage by 0.00%.
The diff coverage is 96.96%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6234      +/-   ##
==========================================
- Coverage   87.37%   87.37%   -0.01%     
==========================================
  Files         143      143              
  Lines      158192   158205      +13     
==========================================
+ Hits       138225   138228       +3     
- Misses      19967    19977      +10     
Impacted Files Coverage Δ
src/quickfix.c 94.97% <96.96%> (-0.04%) ⬇️
src/testing.c 92.56% <0.00%> (-0.64%) ⬇️
src/netbeans.c 75.85% <0.00%> (-0.52%) ⬇️
src/search.c 91.30% <0.00%> (-0.11%) ⬇️
src/ex_getln.c 91.80% <0.00%> (-0.05%) ⬇️
src/window.c 89.14% <0.00%> (+0.03%) ⬆️
src/gui_gtk_x11.c 58.85% <0.00%> (+0.04%) ⬆️
src/gui.c 63.92% <0.00%> (+0.05%) ⬆️
src/sign.c 95.02% <0.00%> (+0.08%) ⬆️
src/if_xcmdsrv.c 88.90% <0.00%> (+0.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e0ebeda...f9440ab. Read the comment docs.

@lacygoill
Copy link

I can confirm that it makes the feature much quicker when dealing with big quickfix lists.

Before the PR, I tested the feature with this QuickFixTextFunc:

fu QuickFixTextFunc(info) abort
    if a:info.quickfix
        let e = getqflist({'id': a:info.id, 'idx': a:info.idx, 'items': 1}).items[0]
    else
        let e = getloclist(0, {'id': a:info.id, 'idx': a:info.idx, 'items': 1}).items[0]
    endif
    let fname = fnamemodify(bufname(e.bufnr), ':t')
    if strchars(fname, 1) <= 8
        let fname = printf('%8s', fname)
    else
        let fname = printf('%.7s', fname)..'…'
    endif
    let lnum = printf('%5d', e.lnum)
    let col = printf('%3d', e.col)
    return fname..'|'..lnum..' col '..col..'| '..e.text
endfu

vim -Nu NONE -S <(curl -Ls https://gist.githubusercontent.com/lacygoill/57d3cd8b5313159f42af43704ebfa7a8/raw/a255cbc37efe18319690943129d0abdf661c1434/profile_quickfixtextfunc.vim)
:QfTf 8

Results:

   1000 entries:   0.001 seconds to run :copen
                   0.039 seconds to run :copen with 'qftf'  39 times slower
   2000 entries:   0.001 seconds to run :copen
                   0.084 seconds to run :copen with 'qftf'  84 times slower
   4000 entries:   0.003 seconds to run :copen
                   0.190 seconds to run :copen with 'qftf'  63 times slower
   8000 entries:   0.006 seconds to run :copen
                   0.457 seconds to run :copen with 'qftf'  76 times slower
  16000 entries:   0.012 seconds to run :copen
                   1.260 seconds to run :copen with 'qftf'  105 times slower
  32000 entries:   0.025 seconds to run :copen
                   4.983 seconds to run :copen with 'qftf'  199 times slower
  64000 entries:   0.054 seconds to run :copen
                  23.322 seconds to run :copen with 'qftf'  431 times slower
 128000 entries:   0.107 seconds to run :copen
                  97.002 seconds to run :copen with 'qftf'  906 times slower

The bigger the quickfix list, the slower the feature.

After the PR, I rewrote the QuickFixTextFunc like this:

fu QuickFixTextFunc(info) abort
    if a:info.quickfix
        let qfl = getqflist({'id': a:info.id, 'items': 1}).items
    else
        let qfl = getloclist(a:info.winid, {'id': a:info.id, 'items': 1}).items
    endif
    let l = []
    for idx in range(a:info.start_idx - 1, a:info.end_idx - 1)
        let e = qfl[idx]
        let fname = fnamemodify(bufname(e.bufnr), ':t')
        if strchars(fname, 1) <= 8
            let fname = printf('%8s', fname)
        else
            let fname = printf('%.7s', fname)..'…'
        endif
        let lnum = printf('%5d', e.lnum)
        let col = printf('%3d', e.col)
        call add(l, fname..'|'..lnum..' col '..col..'| '..e.text)
    endfor
    return l
endfu

./src/vim -Nu NONE -S <(curl -Ls https://gist.githubusercontent.com/lacygoill/57d3cd8b5313159f42af43704ebfa7a8/raw/08926a728e7ee97dee6a426aa6eba11a5869bc2f/profile_quickfixtextfunc.vim)
:QfTf 8

Results:

   1000 entries:   0.002 seconds to run :copen
                   0.037 seconds to run :copen with 'qftf'  18 times slower
   2000 entries:   0.002 seconds to run :copen
                   0.073 seconds to run :copen with 'qftf'  36 times slower
   4000 entries:   0.004 seconds to run :copen
                   0.147 seconds to run :copen with 'qftf'  36 times slower
   8000 entries:   0.011 seconds to run :copen
                   0.300 seconds to run :copen with 'qftf'  27 times slower
  16000 entries:   0.026 seconds to run :copen
                   0.596 seconds to run :copen with 'qftf'  22 times slower
  32000 entries:   0.034 seconds to run :copen
                   1.224 seconds to run :copen with 'qftf'  36 times slower
  64000 entries:   0.077 seconds to run :copen
                   2.605 seconds to run :copen with 'qftf'  33 times slower
 128000 entries:   0.136 seconds to run :copen
                   5.448 seconds to run :copen with 'qftf'  40 times slower

This time, the "slowness" is constant.

Thank you very much @yegappan.

@brammool brammool closed this in 00e260b Jun 11, 2020
kevinhwang91 added a commit to kevinhwang91/neovim that referenced this pull request May 4, 2021
Problem:    Using 'quickfixtextfunc' is a bit slow.
Solution:   Process a list of entries. (Yegappan Lakshmanan, closes vim/vim#6234)
vim/vim@00e260b
kevinhwang91 added a commit to kevinhwang91/neovim that referenced this pull request May 4, 2021
Problem:    Using 'quickfixtextfunc' is a bit slow.
Solution:   Process a list of entries. (Yegappan Lakshmanan, closes vim/vim#6234)
vim/vim@00e260b
kevinhwang91 added a commit to kevinhwang91/neovim that referenced this pull request May 19, 2021
Problem:    Using 'quickfixtextfunc' is a bit slow.
Solution:   Process a list of entries. (Yegappan Lakshmanan, closes vim/vim#6234)
vim/vim@00e260b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants