xrepo env slow without verbose
Xmake Version
dev
Operating System Version and Architecture
Windows 10
Describe Bug
$ hyperfine "xrepo env -v -b msvc shell" "xrepo env -b msvc shell"
Benchmark 1: xrepo env -v -b msvc shell
Time (mean ± σ): 713.1 ms ± 15.2 ms [User: 547.2 ms, System: 318.8 ms]
Range (min … max): 696.9 ms … 740.8 ms 10 runs
Benchmark 2: xrepo env -b msvc shell
Time (mean ± σ): 2.907 s ± 0.265 s [User: 1.833 s, System: 1.366 s]
Range (min … max): 2.615 s … 3.299 s 10 runs
Summary
xrepo env -v -b msvc shell ran
4.08 ± 0.38 times faster than xrepo env -b msvc shell
Expected Behavior
N/A
Project Configuration
N/A
Additional Information and Error Logs
N/A
我看也没慢多少,也就1-2s的样子,xrepo env 每次都会创建一个干净的 empty project 去处理,默认 windows 平台的 msvc 是避免不了的。
PS D:\projects\personal\xmake> xrepo env -vD cmake --version
C:\Program Files (x86)\xmake\xmake.exe create -P .
create working ...
[+]: src\main.cpp
[+]: xmake.lua
[+]: .gitignore
create ok!
checking for platform ... windows
checking for architecture ... x64
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\18\Insiders\VC\Tools\MSVC\14.50.35503\bin\HostX64\x64\cl.exe
checking for Microsoft Visual Studio (x64) version ... 2026
checking for Microsoft C/C++ Compiler (x64) version ... 19.50.35503
checkinfo: cannot runv(nim.exe --version), No such file or directory
checking for nim ... no
checkinfo: cannot runv(nim.exe --version), No such file or directory
checking for nim ... no
checking for git ... C:\Program Files\Git\cmd\git.exe
checkinfo: cannot runv(gzip.exe --version), No such file or directory
checking for gzip ... no
checking for 7z ... D:\projects\personal\xmake\xmake\winenv\bin\7z
checking for curl ... D:\projects\personal\xmake\xmake\winenv\bin\curl
pinging the host(gitlab.com) ... 119 ms
pinging the host(github.com) ... 143 ms
pinging the host(gitee.com) ... 144 ms
C:\Program Files\Git\cmd\git.exe rev-parse HEAD
checking for ninja ... no
checking for ninja ... no
checking for ninja ... no
checkinfo: cannot runv(ninja.exe --version), No such file or directory
checking for ninja ... no
checking for ninja ... C:\Program Files\Microsoft Visual Studio\18\Insiders\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja
checking for cmake ... no
checking for cmake ... no
checking for cmake ... no
checking for cmake ... C:\Program Files\CMake\bin\cmake
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\18\Insiders\VC\Tools\MSVC\14.50.35503\bin\HostX64\x64\cl.exe
checking for the c++ compiler (cxx) ... cl.exe
checking for link.exe ... C:\Program Files\Microsoft Visual Studio\18\Insiders\VC\Tools\MSVC\14.50.35503\bin\HostX64\x64\link.exe
checking for the linker (ld) ... link.exe
cmake version 3.29.0-rc1
只是觉得开了 verbose 更快了有点诡异
这边没明显区别,-vD 下还慢了点
PS D:\projects\personal\xmake> xmake l time xmake l private.xrepo env cmake --version
checking for platform ... windows
checking for architecture ... x64
checking for Microsoft Visual Studio (x64) version ... 2026
checking for Microsoft C/C++ Compiler (x64) version ... 19.50.35503
cmake version 3.29.0-rc1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
time 4.203s
PS D:\projects\personal\xmake> xmake l time xmake l private.xrepo env -vD cmake --version
C:\Program Files (x86)\xmake\xmake.exe create -P .
create working ...
[+]: src\main.cpp
[+]: xmake.lua
[+]: .gitignore
create ok!
checking for platform ... windows
checking for architecture ... x64
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\18\Insiders\VC\Tools\MSVC\14.50.35503\bin\HostX64\x64\cl.exe
checking for Microsoft Visual Studio (x64) version ... 2026
checking for Microsoft C/C++ Compiler (x64) version ... 19.50.35503
checkinfo: cannot runv(nim.exe --version), No such file or directory
checking for nim ... no
checkinfo: cannot runv(nim.exe --version), No such file or directory
checking for nim ... no
checking for git ... C:\Program Files\Git\cmd\git.exe
checkinfo: cannot runv(gzip.exe --version), No such file or directory
checking for gzip ... no
checking for 7z ... D:\projects\personal\xmake\xmake\winenv\bin\7z
checking for curl ... D:\projects\personal\xmake\xmake\winenv\bin\curl
pinging the host(gitlab.com) ... 100 ms
pinging the host(github.com) ... 146 ms
pinging the host(gitee.com) ... 183 ms
C:\Program Files\Git\cmd\git.exe rev-parse HEAD
checking for ninja ... no
checking for ninja ... no
checking for ninja ... no
checkinfo: cannot runv(ninja.exe --version), No such file or directory
checking for ninja ... no
checking for ninja ... C:\Program Files\Microsoft Visual Studio\18\Insiders\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja
checking for cmake ... no
checking for cmake ... no
checking for cmake ... no
checking for cmake ... C:\Program Files\CMake\bin\cmake
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\18\Insiders\VC\Tools\MSVC\14.50.35503\bin\HostX64\x64\cl.exe
checking for the c++ compiler (cxx) ... cl.exe
checking for link.exe ... C:\Program Files\Microsoft Visual Studio\18\Insiders\VC\Tools\MSVC\14.50.35503\bin\HostX64\x64\link.exe
checking for the linker (ld) ... link.exe
cmake version 3.29.0-rc1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
time 4.281s
不太懂,可能和 bat 有关,直接 xmake l private.xrepo 速度就差不多了。
$ hyperfine "xmake l private.xrepo env -v -b msvc shell" "xmake l private.xrepo env -b msvc shell"
Benchmark 1: xmake l private.xrepo env -v -b msvc shell
Time (mean ± σ): 633.2 ms ± 34.7 ms [User: 570.3 ms, System: 259.1 ms]
Range (min … max): 576.0 ms … 681.4 ms 10 runs
Benchmark 2: xmake l private.xrepo env -b msvc shell
Time (mean ± σ): 657.7 ms ± 6.8 ms [User: 540.6 ms, System: 259.1 ms]
Range (min … max): 648.0 ms … 671.5 ms 10 runs
Summary
xmake l private.xrepo env -v -b msvc shell ran
1.04 ± 0.06 times faster than xmake l private.xrepo env -b msvc shell
$ hyperfine "xrepo env -v -b msvc shell" "xrepo env -b msvc shell"
Benchmark 1: xrepo env -v -b msvc shell
Time (mean ± σ): 581.6 ms ± 10.0 ms [User: 500.9 ms, System: 259.4 ms]
Range (min … max): 567.3 ms … 600.6 ms 10 runs
Benchmark 2: xrepo env -b msvc shell
Time (mean ± σ): 2.202 s ± 0.023 s [User: 1.593 s, System: 0.906 s]
Range (min … max): 2.174 s … 2.250 s 10 runs
Summary
xrepo env -v -b msvc shell ran
3.79 ± 0.08 times faster than xrepo env -b msvc shell
Bot detected the issue body's language is not English, translate it automatically.
Just think it's a bit weird if you drive verbose faster
bat 里面额外执行了一些东西
https://github.com/xmake-io/xmake/blob/a8ac81886afa4c174b76016a8e49016eae86ffa8/scripts/xrepo.bat#L24-L28
https://github.com/xmake-io/xmake/blob/a8ac81886afa4c174b76016a8e49016eae86ffa8/scripts/xrepo.bat#L55-L57
Bot detected the issue body's language is not English, translate it automatically.
Something is executed in the bat
https://github.com/xmake-io/xmake/blob/a8ac81886afa4c174b76016a8e49016eae86ffa8/scripts/xrepo.bat#L24-L28
https://github.com/xmake-io/xmake/blob/a8ac81886afa4c174b76016a8e49016eae86ffa8/scripts/xrepo.bat#L55-L57
现在最新版本是直接没生效(执行 cl.exe 失败),只有 verbose 才成功了。
估计还是 xrepo.bat 有问题,xmake l private.xrepo env -b msvc shell 没问题。
所以 xrepo.bat 可以用 xmake lua 重写么,这样可以和多个平台共享同样逻辑,也方便维护,原来的 xrepo.bat 只执行 xmake l xxx 就行。
Bot detected the issue body's language is not English, translate it automatically.
Now the latest version does not take effect directly (executing cl.exe fails), only verbose succeeds.
It is estimated that there is still a problem with xrepo.bat, xmake l private.xrepo env -b msvc shell is fine.
So can xrepo.bat be rewritten with xmake lua, so that it can share the same logic with multiple platforms and facilitate maintenance. The original xrepo.bat only needs to execute xmake l xxx.
所以 xrepo.bat 可以用 xmake lua 重写么,这样可以和多个平台共享同样逻辑,也方便维护,原来的 xrepo.bat 只执行
xmake l xxx就行。
这个就要问 @xq114 了,最早之前,xrepo.bat 就是简单的 wrap xmake l private.xrepo
现在最新版本是直接没生效(执行 cl.exe 失败),只有 verbose 才成功了。 估计还是 xrepo.bat 有问题,xmake l private.xrepo env -b msvc shell 没问题。
不是可以的么
PS D:\projects\xxx> xrepo env -b msvc shell
checking for platform ... windows
checking for architecture ... x64
checking for Microsoft C/C++ Compiler (x64) ... ok
checking for Microsoft Visual Studio (x64) version ... 2026
[msvc] PS D:\projects\personal> cl
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.50.35503 版
版权所有(C) Microsoft Corporation。保留所有权利。
用法: cl [ 选项... ] 文件名... [ /link 链接选项... ]
Bot detected the issue body's language is not English, translate it automatically.
So xrepo.bat can be rewritten with xmake lua, so that it can share the same logic with multiple platforms and facilitate maintenance. The original xrepo.bat only needs to execute
xmake l xxx.
I have to ask @xq114 about this. Previously, xrepo.bat was simply wrap xmake l private.xrepo
现在最新版本是直接没生效(执行 cl.exe 失败),只有 verbose 才成功了。 估计还是 xrepo.bat 有问题,xmake l private.xrepo env -b msvc shell 没问题。
不是可以的么
PS D:\projects\xxx> xrepo env -b msvc shell checking for platform ... windows checking for architecture ... x64 checking for Microsoft C/C++ Compiler (x64) ... ok checking for Microsoft Visual Studio (x64) version ... 2026 [msvc] PS D:\projects\personal> cl 用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.50.35503 版 版权所有(C) Microsoft Corporation。保留所有权利。 用法: cl [ 选项... ] 文件名... [ /link 链接选项... ]
抱歉,忘记提到,是用 nushell 进行的测试,cmd 应该是没问题的。
现在最新版本是直接没生效(执行 cl.exe 失败),只有 verbose 才成功了。 估计还是 xrepo.bat 有问题,xmake l private.xrepo env -b msvc shell 没问题。
不是可以的么
PS D:\projects\xxx> xrepo env -b msvc shell checking for platform ... windows checking for architecture ... x64 checking for Microsoft C/C++ Compiler (x64) ... ok checking for Microsoft Visual Studio (x64) version ... 2026 [msvc] PS D:\projects\personal> cl 用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.50.35503 版 版权所有(C) Microsoft Corporation。保留所有权利。 用法: cl [ 选项... ] 文件名... [ /link 链接选项... ]抱歉,忘记提到,是用 nushell 进行的测试,cmd 应该是没问题的。
nushell 从没支持过吧,只支持 cmd 和 powershell,xrepo 的 wrapper 也只提供了这两,在 nushell 里我都跑不起,语法都过不了。
d:\projects\personal\xmake> xrepo env -b msvc shell
此时不应有 \xmake\。
d:\projects\personal\xmake> pushd C:\Program Files (x86)\xmake\
Bot detected the issue body's language is not English, translate it automatically.
Now the latest version does not take effect directly (executing cl.exe fails), only verbose succeeds. It is estimated that there is still a problem with xrepo.bat, xmake l private.xrepo env -b msvc shell is fine.
Isn’t it possible?
PS D:\projects\xxx> xrepo env -b msvc shell checking for platform ... windows checking for architecture ... x64 checking for Microsoft C/C++ Compiler (x64) ... ok checking for Microsoft Visual Studio (x64) version ... 2026 [msvc] PS D:\projects\personal> cl Microsoft (R) C/C++ Optimizing Compiler for x64 version 19.50.35503 Copyright (C) Microsoft Corporation. All rights reserved. Usage: cl [options...] filename... [/link link options...]Sorry, I forgot to mention that the test was conducted with nushell, cmd should be no problem.
Nushell has never supported it. It only supports cmd and powershell. The wrapper of xrepo only provides these two. I can't run it in nushell, and I can't pass the grammar.
d:\projects\personal\xmake> xrepo env -b msvc shell
There should be no \xmake\ at this time.
d:\projects\personal\xmake> pushd C:\Program Files (x86)\xmake\
所以 xrepo.bat 可以用 xmake lua 重写么,这样可以和多个平台共享同样逻辑,也方便维护,原来的 xrepo.bat 只执行 xmake l xxx 就行。
逻辑目前就是通用的,仅仅只是 xrepo.bat 和 xrepo.ps1 里面额外加了 prompt 的获取和设置。
而 xrepo.sh 是因为 bash 可以在 xmake 内部起 shell 时候就就设置好 prompt ,所以没有这些逻辑。
不过我看 cmd 下也能内部设置 prompt,为啥还需要 xrepo.bat 里面处理,我就不清楚了 。@xq114
Bot detected the issue body's language is not English, translate it automatically.
So xrepo.bat can be rewritten with xmake lua, so that it can share the same logic with multiple platforms and facilitate maintenance. The original xrepo.bat only needs to execute xmake l xxx.
The logic is currently universal, except that xrepo.bat and xrepo.ps1 additionally add the acquisition and setting of prompt.
xrepo.sh is because bash can set prompt when starting the shell inside xmake, so there is no such logic.
However, I see that prompt can also be set internally under cmd. Why it needs to be processed in xrepo.bat, I don’t know. @xq114
xrepo.bat里设置的环境变量PROMPT可以在外面生效,一旦进了xmake进程了设置的环境变量就和外界环境无关了。powershell也类似,需要注册一个powershell module才能加PROMPT,这些逻辑目前只支持xrepo env -b xxx shell这种形式的命令,没写command line parser,因此加-v不会走PROMPT逻辑,也不能让环境变量正常生效。如果需要-v的话需要在里面加一个command line parser
bash虽然可以通过在xmake内部再调用一次bash实现改环境变量,但这样得到的bash环境和原bash不是同一个,命令历史等等都不继承,而且不小心按到Ctrl+C直接回到原来bash环境这个环境就丢失了。所以现在bash是在user profile里注册了一个xrepo函数来实现就地更改,并非调用xrepo.sh
powershell module第一次加载的时候比较慢,后面同一个shell环境不用重复加载会快一点。这部分逻辑主要参考的anaconda的实现,我不清楚有没有更好的实现方式
Bot detected the issue body's language is not English, translate it automatically.
Although bash can change environment variables by calling bash again inside xmake, the bash environment obtained in this way is not the same as the original bash, and the command history and so on are not inherited. If you accidentally press Ctrl+C to directly return to the original bash environment, the environment will be lost. So now bash registers an xrepo function in the user profile to implement in-place changes, instead of calling xrepo.sh
Bot detected the issue body's language is not English, translate it automatically.
The powershell module is slow to load for the first time. It will be faster if the same shell environment is not loaded again later. This part of the logic mainly refers to the implementation of anaconda. I don’t know if there is a better implementation.
bash虽然可以通过在xmake内部再调用一次bash实现改环境变量,但这样得到的bash环境和原bash不是同一个,命令历史等等都不继承,而且不小心按到Ctrl+C直接回到原来bash环境这个环境就丢失了。所以现在bash是在user profile里注册了一个xrepo函数来实现就地更改,并非调用xrepo.sh
那就是 bash 下现在用的是 https://github.com/xmake-io/xmake/blob/4253fdd36cf2b4de908466b24da608a865fe9400/xmake/scripts/virtualenvs/register-virtualenvs.sh#L28
xrepo.sh 弃用了
Bot detected the issue body's language is not English, translate it automatically.
Although bash can change environment variables by calling bash again inside xmake, the bash environment obtained in this way is not the same as the original bash, and the command history and so on are not inherited. If you accidentally press Ctrl+C to directly return to the original bash environment, the environment will be lost. So now bash registers an xrepo function in the user profile to implement in-place changes, instead of calling xrepo.sh
That is, what is currently used under bash is https://github.com/xmake-io/xmake/blob/4253fdd36cf2b4de908466b24da608a865fe9400/xmake/scripts/virtualenvs/register-virtualenvs.sh#L28
xrepo.sh is deprecated
powershell module第一次加载的时候比较慢,后面同一个shell环境不用重复加载会快一点。这部分逻辑主要参考的anaconda的实现,我不清楚有没有更好的实现方式
慢,应该是执行 xmake 进程次数过多导致的,win 起进程原本就比较重。
https://github.com/xmake-io/xmake/blob/4253fdd36cf2b4de908466b24da608a865fe9400/scripts/xrepo.bat#L41-L57
这里的多个 xmake lua 执行,是否可以做一些合并,减少一些调用次数,应该会快点。
Bot detected the issue body's language is not English, translate it automatically.
The powershell module is slow to load for the first time. It will be faster if the same shell environment is not loaded again later. This part of the logic mainly refers to the implementation of anaconda. I don’t know if there is a better implementation.
Slowness may be caused by executing the xmake process too many times. The win process is inherently heavier.
https://github.com/xmake-io/xmake/blob/4253fdd36cf2b4de908466b24da608a865fe9400/scripts/xrepo.bat#L41-L57
For the multiple xmake lua executions here, can we do some merging and reduce the number of calls? It should be faster.