-
-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: Improve clink startup speed #383
Comments
看了一下, 似乎是每次执行命令的时候都要执行一遍 env? |
我自己用clink,加了clink_vfox.lua之后,明显感觉变慢了,性能比较差,不知道是不是个例现象 |
@ViCrack 是敲 vfox/internal/shell/clink_vfox.lua Lines 2 to 16 in ca4d9e6
|
我昨晚试了试 clink,是启动慢了,需要 1s 左右才能输入
获取Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: janbar ***@***.***>
Sent: Monday, December 23, 2024 3:01:09 PM
To: version-fox/vfox ***@***.***>
Cc: DarkRRb ***@***.***>; Author ***@***.***>
Subject: Re: [version-fox/vfox] [Feature]: Support cmd on Windows (Issue #383)
我自己用clink,加了clink_vfox.lua之后,明显感觉变慢了,性能比较差,不知道是不是个例现象
@ViCrack<https://github.com/ViCrack> 是敲vfox xxx命令时慢了点,还是任何命令都慢啊?因为做了vfox命令自动补全,最新clink_vfox.lua会在首次执行vfox命令时执行vfox available从网络获取支持的编程语言列表,但后面再执行vfox命令时不会受影响。可以自己修改lua代码,手动添加常用编程语言到vfox_sdk_table变量里面,这样可以避免网络影响额。
https://github.com/version-fox/vfox/blob/ca4d9e6989b45d394dad05609aa80503cd72b76c/internal/shell/clink_vfox.lua#L2-L16
―
Reply to this email directly, view it on GitHub<#383 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BKKTDFXFQLCZ3RI2P3DUO6L2G6YLLAVCNFSM6AAAAABUB3IDT6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNJZGAZTIMBZG4>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
@jan-bar 是启动慢了,慢得能跟powershell比了。这里vfox available是否能实现做个时间缓存啥的,不需要每次都从网络获取吧。 另外如果只用cmd的话,执行vfox use -g java@8也会比较慢 如下图, |
不知道这个 sdk 列表是不是只是为了补全,如果只补全的话可否移动到补全的时候执行?clink 的补全似乎是异步的,同时做好缓存?
获取Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: janbar ***@***.***>
Sent: Monday, December 23, 2024 3:01:09 PM
To: version-fox/vfox ***@***.***>
Cc: DarkRRb ***@***.***>; Author ***@***.***>
Subject: Re: [version-fox/vfox] [Feature]: Support cmd on Windows (Issue #383)
我自己用clink,加了clink_vfox.lua之后,明显感觉变慢了,性能比较差,不知道是不是个例现象
@ViCrack<https://github.com/ViCrack> 是敲vfox xxx命令时慢了点,还是任何命令都慢啊?因为做了vfox命令自动补全,最新clink_vfox.lua会在首次执行vfox命令时执行vfox available从网络获取支持的编程语言列表,但后面再执行vfox命令时不会受影响。可以自己修改lua代码,手动添加常用编程语言到vfox_sdk_table变量里面,这样可以避免网络影响额。
https://github.com/version-fox/vfox/blob/ca4d9e6989b45d394dad05609aa80503cd72b76c/internal/shell/clink_vfox.lua#L2-L16
―
Reply to this email directly, view it on GitHub<#383 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BKKTDFXFQLCZ3RI2P3DUO6L2G6YLLAVCNFSM6AAAAABUB3IDT6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNJZGAZTIMBZG4>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
测试了一下, 似乎是 |
|
图片提示的错误 Warning: The current shell lacks hook support or configuration. It has switched to global scope automatically. 这里我是去掉了那个clink_vfox.lua后的测试结果,我是故意没执行lua的,看看默认情况下cmd用 -g的速度 |
|
|
突然意识到, 并不是这里慢, 是 |
vfox/internal/shell/clink_vfox.lua Lines 119 to 125 in ca4d9e6
下面是我改进的代码,不知道可行不,lua可以用异步协程来执行命令,这样启动就不会有明显的卡顿了
下面是整个lua文件的内容 |
下面是我的方案,主要修改3个地方
-- https://chrisant996.github.io/clink/clink.html#extending-clink
local vfox_sdk_table = {}
clink.argmatcher('vfox'):nofiles():setdelayinit(function(vfox)
if #vfox_sdk_table ~= 0 then
return
end
local file_name = 'available.txt'
local file_available = io.open(file_name, 'r')
if file_available then
for line in file_available:lines() do
table.insert(vfox_sdk_table, line)
end
else
file_available = io.open(file_name, 'w')
local vfox_available = io.popen('vfox available')
for line in vfox_available:lines() do
local trim = line:gsub('%c%[%d+m', '')
local name = trim:match('^(%S+)')
if name and (trim:find('YES') or trim:find('NO')) then
table.insert(vfox_sdk_table, name)
file_available:write(name .. '\n')
end
end
vfox_available:close()
end
file_available:close()
local function vfox_ls_func()
local pre, ls = '', {}
local vfox_ls = io.popen('vfox ls')
for line in vfox_ls:lines() do
local txt = line:gsub('%c%[%d+m', ''):match('^%A+(%a.+)')
if txt then
if txt:find('v') == 1 then
ls[pre] = true
table.insert(ls, pre .. '@' .. txt:sub(2))
else
pre = txt
ls[pre] = false
end
end
end
vfox_ls:close()
return ls
end
local function vfox_sdk_func()
local ls, res = vfox_ls_func(), {}
for k, v in pairs(ls) do
if type(v) == 'boolean' then
table.insert(res, k)
end
end
return res
end
local vfox_sdk = clink.argmatcher():nofiles():addarg(vfox_sdk_func):addflags('--help', '-h')
local vfox_use = clink.argmatcher():nofiles():addarg(function()
local ls, res = vfox_ls_func(), {}
for k, v in pairs(ls) do
if v then
table.insert(res, v == true and k or v)
end
end
return res
end):addflags('--global', '-g', '--session', '-s', '--project', '-p', '--help', '-h')
local vfox_help = clink.argmatcher():nofiles():addflags('--help', '-h')
local vfox_shell = clink.argmatcher():nofiles():addarg('bash', 'zsh', 'pwsh', 'fish', 'clink')
local vfox_uninstall = clink.argmatcher():nofiles():addarg(vfox_ls_func):addflags('--help', '-h')
local vfox_install = clink.argmatcher():nofiles():addarg({
onadvance = function() return 0 end,
vfox_sdk_func,
}):addflags('--all', '-a', '--help', '-h')
vfox:addarg(
'add' .. clink.argmatcher():nofiles():addarg({
onadvance = function() return 0 end,
function(word, word_index, line_state)
local res, line = {}, line_state:getline()
for _, v in ipairs(vfox_sdk_table) do
if not line:find(v) then
table.insert(res, v)
end
end
return res
end
}):addflags('--source', '-s', '--alias', '--help', '-h'),
'use' .. vfox_use, 'u' .. vfox_use,
'info' .. vfox_sdk,
'remove' .. vfox_sdk,
'search' .. vfox_sdk,
'update' .. clink.argmatcher():nofiles():addarg(vfox_sdk_func):addflags('--all', '-a', '--help', '-h'),
'available' .. vfox_help,
'upgrade' .. vfox_help,
'current' .. vfox_sdk, 'c' .. vfox_sdk,
'list' .. vfox_sdk, 'ls' .. vfox_sdk,
'uninstall' .. vfox_uninstall, 'un' .. vfox_uninstall,
'install' .. vfox_install, 'i' .. vfox_install,
'env' .. clink.argmatcher():nofiles():addflags(
'--shell' .. vfox_shell, '-s' .. vfox_shell,
'--cleanup', '-c',
'--json', '-j',
'--help', '-h'
),
'activate' .. vfox_shell,
'config' .. clink.argmatcher():nofiles():addarg(function()
local res, vfox_config = {}, io.popen('vfox config -l')
for line in vfox_config:lines() do
local txt = line:gsub('%c%[%d+m', ''):match('^(%S+)')
if txt then
table.insert(res, txt)
end
end
vfox_config:close()
return res
end):addflags('--list', '-l', '--unset', '-un', '--help', '-h'),
'cd' .. clink.argmatcher():nofiles():addarg(vfox_sdk_func):addflags('--plugin', '-p', '--help', '-h'),
'help', 'h'
):addflags('--debug', '--help', '-h', '--version', '-v', '-V')
end)
local vfox_setenv = function(str)
local key, val = str:match('^set "(.+)=(.*)"')
if key and val then
return os.setenv(key, val ~= '' and val or nil)
end
end
local task = coroutine.create(function()
local vfox_activate = io.popen('vfox activate clink')
for line in vfox_activate:lines() do
vfox_setenv(line)
end
vfox_activate:close()
os.setenv('__VFOX_PID', os.getpid())
os.execute('vfox env -c')
end)
coroutine.resume(task)
local vfox_prompt = clink.promptfilter(30)
function vfox_prompt:filter(prompt)
clink.promptcoroutine(function()
local env = io.popen('vfox env -s clink')
for line in env:lines() do
vfox_setenv(line)
end
env:close()
end)
end @DarkRRb 你可以用上面脚本测试看看额 |
我自己试了上面的脚本,启动耗时已经几乎无感了。 另外vfox available这样应该也没必要缓存了,除非加上时间过期,不然以后内容可能不会及时更新。 |
是否需要考虑更新的问题? 异步跑一个更新检测? |
-- https://chrisant996.github.io/clink/clink.html#extending-clink
local vfox_sdk_table = {}
clink.argmatcher('vfox'):nofiles():setdelayinit(function(vfox)
if #vfox_sdk_table ~= 0 then
return
end
local use_cmd = true
local current_timestamp = os.time()
local file_name = os.getenv("USERPROFILE") .. '\\available.txt'
local file_available = io.open(file_name, 'r')
if file_available then
local file_timestamp = tonumber(file_available:read('*l'))
if current_timestamp - file_timestamp <= 24 * 60 * 60 then
for line in file_available:lines() do
table.insert(vfox_sdk_table, line)
end
use_cmd = false
end
file_available:close()
end
if use_cmd then
file_available = io.open(file_name, 'w')
file_available:write(current_timestamp .. '\n')
local vfox_available = io.popen('vfox available')
for line in vfox_available:lines() do
local trim = line:gsub('%c%[%d+m', '')
local name = trim:match('^(%S+)')
if name and (trim:find('YES') or trim:find('NO')) then
table.insert(vfox_sdk_table, name)
file_available:write(name .. '\n')
end
end
vfox_available:close()
file_available:close()
end
local function vfox_ls_func()
local pre, ls = '', {}
local vfox_ls = io.popen('vfox ls')
for line in vfox_ls:lines() do
local txt = line:gsub('%c%[%d+m', ''):match('^%A+(%a.+)')
if txt then
if txt:find('v') == 1 then
ls[pre] = true
table.insert(ls, pre .. '@' .. txt:sub(2))
else
pre = txt
ls[pre] = false
end
end
end
vfox_ls:close()
return ls
end
local function vfox_sdk_func()
local ls, res = vfox_ls_func(), {}
for k, v in pairs(ls) do
if type(v) == 'boolean' then
table.insert(res, k)
end
end
return res
end
local vfox_sdk = clink.argmatcher():nofiles():addarg(vfox_sdk_func):addflags('--help', '-h')
local vfox_use = clink.argmatcher():nofiles():addarg(function()
local ls, res = vfox_ls_func(), {}
for k, v in pairs(ls) do
if v then
table.insert(res, v == true and k or v)
end
end
return res
end):addflags('--global', '-g', '--session', '-s', '--project', '-p', '--help', '-h')
local vfox_help = clink.argmatcher():nofiles():addflags('--help', '-h')
local vfox_shell = clink.argmatcher():nofiles():addarg('bash', 'zsh', 'pwsh', 'fish', 'clink')
local vfox_uninstall = clink.argmatcher():nofiles():addarg(vfox_ls_func):addflags('--help', '-h')
local vfox_install = clink.argmatcher():nofiles():addarg({
onadvance = function() return 0 end,
vfox_sdk_func,
}):addflags('--all', '-a', '--help', '-h')
vfox:addarg(
'add' .. clink.argmatcher():nofiles():addarg({
onadvance = function() return 0 end,
function(word, word_index, line_state)
local res, line = {}, line_state:getline()
for _, v in ipairs(vfox_sdk_table) do
if not line:find(v) then
table.insert(res, v)
end
end
return res
end
}):addflags('--source', '-s', '--alias', '--help', '-h'),
'use' .. vfox_use, 'u' .. vfox_use,
'info' .. vfox_sdk,
'remove' .. vfox_sdk,
'search' .. vfox_sdk,
'update' .. clink.argmatcher():nofiles():addarg(vfox_sdk_func):addflags('--all', '-a', '--help', '-h'),
'available' .. vfox_help,
'upgrade' .. vfox_help,
'current' .. vfox_sdk, 'c' .. vfox_sdk,
'list' .. vfox_sdk, 'ls' .. vfox_sdk,
'uninstall' .. vfox_uninstall, 'un' .. vfox_uninstall,
'install' .. vfox_install, 'i' .. vfox_install,
'env' .. clink.argmatcher():nofiles():addflags(
'--shell' .. vfox_shell, '-s' .. vfox_shell,
'--cleanup', '-c',
'--json', '-j',
'--help', '-h'
),
'activate' .. vfox_shell,
'config' .. clink.argmatcher():nofiles():addarg(function()
local res, vfox_config = {}, io.popen('vfox config -l')
for line in vfox_config:lines() do
local txt = line:gsub('%c%[%d+m', ''):match('^(%S+)')
if txt then
table.insert(res, txt)
end
end
vfox_config:close()
return res
end):addflags('--list', '-l', '--unset', '-un', '--help', '-h'),
'cd' .. clink.argmatcher():nofiles():addarg(vfox_sdk_func):addflags('--plugin', '-p', '--help', '-h'),
'help', 'h'
):addflags('--debug', '--help', '-h', '--version', '-v', '-V')
end)
local vfox_setenv = function(str)
local key, val = str:match('^set "(.+)=(.*)"')
if key and val then
return os.setenv(key, val ~= '' and val or nil)
end
end
local task = coroutine.create(function()
local vfox_activate = io.popen('vfox activate clink')
for line in vfox_activate:lines() do
vfox_setenv(line)
end
vfox_activate:close()
os.setenv('__VFOX_PID', os.getpid())
os.execute('vfox env -c')
end)
coroutine.resume(task)
local vfox_prompt = clink.promptfilter(30)
function vfox_prompt:filter(prompt)
clink.promptcoroutine(function()
local env = io.popen('vfox env -s clink')
for line in env:lines() do
vfox_setenv(line)
end
env:close()
end)
end @ViCrack @DarkRRb 添加代码,文件不存在或文件时间戳和当前时间相差超过24小时,这两种情况会使用命令获取最新列表,过期时间可自行修改源码进行指定。 |
1. Your usage scenarios?
PowerShell 启动太慢了, 我是直接使用的 CMD, 但目前没有支持 CMD
可以参考 fnm 配置 CMD 的方式操作
2. What is your expected outcome?
支持 CMD
The text was updated successfully, but these errors were encountered: