-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: avoid copying buffer/window variables to lua
Problem: Calling vim.fn.{getbufinfo,getwininfo} in lua can be slow because it has to convert potentially big and cyclic data structures stored in vim buffer/window variables into lua values. Solution: Remove buffer/window variables from the result before passing it to lua.
- Loading branch information
Showing
5 changed files
with
36 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
" Calling vim.fn.getbufinfo in lua can be expensive because it has to convert | ||
" all the buffer variables into lua values. Since fzf-lua does not access | ||
" buffer variables, this cost can be avoided by clearing the entry before | ||
" passing the info to lua. | ||
function! fzf_lua#getbufinfo(bufnr) abort | ||
let info = getbufinfo(a:bufnr) | ||
if empty(info) | ||
return v:false " there is no way to return `nil` from vimscript | ||
endif | ||
unlet! info[0].variables | ||
return info[0] | ||
endfunction | ||
|
||
" Similar to fzf_lua#getbufinfo, but for getwininfo. | ||
function! fzf_lua#getwininfo(winid) abort | ||
let info = getwininfo(a:winid) | ||
if empty(info) | ||
return v:false | ||
endif | ||
unlet! info[0].variables | ||
return info[0] | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters