neovim / neovim

Vim-fork focused on extensibility and usability
https://neovim.io
Other
82.58k stars 5.66k forks source link

nvim_get_runtime_file is very slow when using a glob with `{A,B,C}` #18838

Closed ModProg closed 1 year ago

ModProg commented 2 years ago

Neovim version (nvim -v)

v0.8.0-dev+207-g0adc66171

Vim (not Nvim) behaves the same?

no, lua :)

Operating system/version

Arch Linux

Terminal name/version

wezterm 20220528-212940-84842aaa

$TERM environment variable

xterm-256color

Installation

AUR

How to reproduce the issue

Compare how long

nvim -u NONE --cmd "lua vim.api.nvim_get_runtime_file('config/*.{yaml,yml,json}', true)" "+:q"

and

nvim -u NONE --cmd "lua vim.api.nvim_get_runtime_file('config/*.yaml', true) | lua vim.api.nvim_get_runtime_file('config
/*.yml', true) | lua vim.api.nvim_get_runtime_file('config/*.json', true) " "+:q"

take

Expected behavior

Both should perform similarly fast.

Actual behavior

❯ time nvim -u NONE --cmd "lua vim.api.nvim_get_runtime_file('config/*.yaml', true) | lua vim.api.nvim_get_runtime_file('config
/*.yml', true) | lua vim.api.nvim_get_runtime_file('config/*.json', true) " "+:q"

________________________________________________________
Executed in   20.79 millis    fish           external
   usr time    7.76 millis  128.00 micros    7.63 millis
   sys time    3.31 millis   45.00 micros    3.27 millis

~
❯ time nvim -u NONE --cmd "lua vim.api.nvim_get_runtime_file('config/*.{yaml,yml,json}', true)" "+:q"

________________________________________________________
Executed in  148.62 millis    fish           external
   usr time  108.54 millis  158.00 micros  108.38 millis
   sys time   42.69 millis   62.00 micros   42.63 millis

With the braces it takes a lot longer, even though it should be doing the same amount of work roughly.

And the difference is a lot bigger when measuring the functions directly:

I made a small test plugin, and it shows a difference of about a factor of 150 (times in µs): grafik

The plugin is writen in rust with my own bindings, but someone knowledgeable in Lua should be able to write an easier to run test there as well: https://github.com/ModProg/nvim-perf-runtime_file/blob/c84070386220cfc43ce300acdd66fa0b3f05690f/src/lib.rs#L12-L28

lewis6991 commented 2 years ago

My guess is due to the syntax used, it is shelling out to bash to perform the glob. You're probably better off just calling nvim_get_runtime several times.

ModProg commented 2 years ago

My guess is due to the syntax used, it is shelling out to bash to perform the glob. You're probably better off just calling nvim_get_runtime several times.

Makes sense, it's what I opted to do for now as well

zeertzjq commented 1 year ago

Fixed by #24296