aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/pack.lua
diff options
context:
space:
mode:
authorEvgeni Chasnovski <evgeni.chasnovski@gmail.com>2026-04-05 20:06:00 +0300
committerGitHub <noreply@github.com>2026-04-05 13:06:00 -0400
commit3cba8df0412706d5803ac194bb26ba882dcd039d (patch)
tree237947c665c67ea44cc9619ecaa9cba608b88ce8 /runtime/lua/vim/pack.lua
parent9705a1c13b04c20a6b8eb1f57d543f4d08240876 (diff)
downloadrneovim-3cba8df0412706d5803ac194bb26ba882dcd039d.tar.gz
rneovim-3cba8df0412706d5803ac194bb26ba882dcd039d.tar.bz2
rneovim-3cba8df0412706d5803ac194bb26ba882dcd039d.zip
fix(pack): use `uv.available_parallelism()` to compute number of threads #38717
Problem: Computing number of threads for parallel asynchronous computation using `uv.cpu_info()` can be slow. This is especially noticeable since it is pre-computed on every `require('vim.pack')` and not only when parallelism is needed. Solution: Use `uv.available_parallelism()` to compute number of threads in a helper function.
Diffstat (limited to 'runtime/lua/vim/pack.lua')
-rw-r--r--runtime/lua/vim/pack.lua24
1 files changed, 11 insertions, 13 deletions
diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua
index 8284767cfe..3a5545cd63 100644
--- a/runtime/lua/vim/pack.lua
+++ b/runtime/lua/vim/pack.lua
@@ -499,9 +499,17 @@ local function new_progress_report(action)
end)
end
-local n_threads = 2 * #(uv.cpu_info() or { {} })
local copcall = package.loaded.jit and pcall or require('coxpcall').pcall
+local function async_join_run_wait(funs)
+ local n_threads = 2 * (uv.available_parallelism() or 1)
+ --- @async
+ local function joined_f()
+ async.join(n_threads, funs)
+ end
+ async.run(joined_f):wait()
+end
+
--- Execute function in parallel for each non-errored plugin in the list
--- @param plug_list vim.pack.Plug[]
--- @param f async fun(p: vim.pack.Plug)
@@ -536,13 +544,7 @@ local function run_list(plug_list, f, progress_action)
-- Run async in parallel but wait for all to finish/timeout
report_progress('begin', 0, '(0/%d)', #funs)
-
- --- @async
- local function joined_f()
- async.join(n_threads, funs)
- end
- async.run(joined_f):wait()
-
+ async_join_run_wait(funs)
report_progress('end', 100, '(%d/%d)', #funs, #funs)
end
@@ -1407,11 +1409,7 @@ local function add_p_data_info(p_data_list)
p_data.tags = git_get_tags(path)
end
end
- --- @async
- local function joined_f()
- async.join(n_threads, funs)
- end
- async.run(joined_f):wait()
+ async_join_run_wait(funs)
end
--- Gets |vim.pack| plugin info, optionally filtered by `names`.