goolord / alpha-nvim

a lua powered greeter like vim-startify / dashboard-nvim
MIT License
1.92k stars 113 forks source link

refactor: replace `utils.from_nil` with `vim.F.if_nil` #7

Closed l-kershaw closed 3 years ago

l-kershaw commented 3 years ago

There is an if_nil function built in to neovim already, so don't need to redefine one. (Defined here)

goolord commented 3 years ago

are files in neovim/runtime meant to provide a stable api or is this moudle internal? it being undocumented makes me a bit skeptical of its use, anyways

goolord commented 3 years ago

i pushed a commit that locally scopes vim.F.if_nil. conventional wisdom is that luajit doesn't cache table lookups so this

for i = 1, 100 do
  vim.F.if_nil(nil,nil)
end

does 200 lookups and this

local if_nil = vim.F.if_nil
for i = 1, 100
  if_nil(nil,nil)
end

does 2

l-kershaw commented 3 years ago

@goolord thanks for merging 🙂


My understanding is that the vim.F stuff is meant so that people don't have to rewrite the same functions everywhere. It seems to be used both internally in neovim and in a range of plugins (see here).


I am not 100% confident on how LuaJIT responds to this sort of thing. My previous understanding was that it would handle this without a load of repeated lookups, but in any case your commit definitely won't hurt performance, so no problems here 👍

goolord commented 3 years ago

there is a section about this on page 3 of https://www.lua.org/gems/sample.pdf