Skip to content

[P2][perf] the shipped git.exe launcher adds ~114ms per invocation: time git 202ms vs 32ms direct, Git Bash does 68ms #8

Closed

Description

@caomengxuan666

Owner directive(2026-10-14)

time git 对比实测:niu 内 202ms vs Git Bash 68ms(同机同命令,usage 输出)。owner 猜测"可能是我们的这个git转发太多了?可能需要改NIUGIT仓库之类的"——方向正确,数据已定位。

测量分解(DESKTOP-FDUJ7TN,2026-10-14)

测量 耗时 说明
niu 内 time git(经 launcher) 202ms git 解析到 winuxcmd\usr\bin\git.exe(4MB launcher,4013056 bytes @ 2026-10-03)
niu 内 time <opt/niugit/git.exe> 直打真身 32ms 比 Git Bash 快 2 倍
PowerShell 同表对照:launcher 145ms 三者等含 PS spawn 开销
PowerShell 同表对照:真 niugit 31ms
PowerShell 同表对照:Git for Windows 2.55(D:\Git\cmd\git.exe) 41ms 参照

结论:壳(rubash spawn)与 niugit 本体都无罪(31ms 优于 GfW 的 41ms);launcher 一跳吃掉 ~114ms(145-31),占总耗时 60%。4MB 的 rust launcher 不该有这个量级的启动成本。

修复方向(按优先级)

  1. 评估直接消掉这一跳:真 niugit 是 GfW 系构建,自定位安装根(实测任意 cwd 直跑 usage 正常)——若仓库操作/钩子场景验证通过,PATH 位的 usr/bin/git.exe 可以像 wpm 其他注册命令一样直接硬链接到 opt/niugit/git.exe(GfW 自己的 cmd\git.exe 就是真身非 wrapper)。验证面:git clone/hook 执行/git submodule/credential helper 从非安装 cwd 全链跑通。
  2. 若 launcher 必须留(它设置的某环境真身自给不了):profile 它的 114ms 花在哪——4MB rust 启动正常应在个位数 ms;嫌疑=内部再起中间进程(三跳?)、环境探测扫描、或每次 spawn 的 AV 扫描放大。修到个位数后 202→~90ms 也达 GfW 水平以下。

关联

  • 与 rubash#375(spawn 地板)正交——本票数据里 spawn 地板不是主项(202-145=57ms 是 niu spawn+真 git 的合理和)。
  • 修复后指标:niu 内 time git ≤ ~90ms(保守,保 launcher)或 ~50ms(消跳)——均优于 Git Bash 68ms。

环境:Niubash 1.4.0(niu.exe @ 20ec3ef0 构建)、niugit 2.55.0.4(wpm 装)。

Activity

  1. changed the title [-][P2][perf] the shipped git.exe launcher costs ~114ms per invocation - 6x the real binary; time git 202ms vs Git Bash 68ms[/-] [+][P2][perf] the shipped git.exe launcher adds ~114ms per invocation: time git 202ms vs 32ms direct, Git Bash does 68ms[/+] on Oct 14, 2026
  2. added
    P2
    on Oct 15, 2026
  3. caomengxuan666 commented on Oct 16, 2026

    @caomengxuan666
    MemberAuthor

    已修复并发布:v2.55.0.5(launcher 这一跳被彻底消掉)

    修复方向 1 落地,而且不是「硬链接到 launcher」,是让真身直接站在 PATH 位上:

    • wpm 侧走 layout: flat:包的 mingw64/bin/git.exe 直接映射到 <root>/usr/bin/git.exe(usr/bin/git.exe 现在就是 5,203,968 字节的真 git 本体,不再是 4MB launcher,也没有 winuxcmd 分派跳);
    • niu-git 侧新增 patch 0003(system_prefix 自定位):剥离路径得到的前缀先用 <prefix>/<GIT_EXEC_PATH> 校验,不成立就向上探测 payload 标记(opt/niugit/mingw64、mingw64)→ 因此「裸二进制 + 非安装 cwd」也能找到 exec-path/templates/系统配置,不需要 launcher 帮它设环境。正常 MinGit/构建树布局仍走原路径(只多一次 is_directory,字节级不变)。

    本票指标实测(同机,niu 内 time git)

    指标 目标 实测
    time git --version(niu 内) ≤ ~50ms 18 / 22 / 23 ms(基线 202ms)
    time git status --porcelain(niu 内,热) — 27 / 28 / 35 ms
    直接跑真身(Python 计时,15 次) — 13.7 ms 均值 / 11.5 ms 最低
    Git Bash 参照 — 68 ms

    即 比目标还快约 3 倍,也优于 Git Bash。附带:git.exe 的导入表只剩系统 DLL(zlib/iconv 静态链接),libcurl/zlib/libexpat 放在 libexec/git-core(不在 PATH),所以这一跳消掉的同时 DLL 搜索路径也不再需要环境布设。

    本票列出的验证面(均在非安装 cwd,/tmp)逐项通过

    • git clone(本地传输,dashed helper 经 exec-path 找到)✅
    • hook 执行(pre-commit 经 PATH 上的 sh 运行,输出 HOOK-RAN)✅
    • git submodule add / submodule status ✅
    • https:git ls-remote https://github.com/unixwin/niu-git HEAD ✅
    • --exec-path / config --system --list / templates ✅
    • 凭据:helper 经 exec-path 可解析;当前安装的 payload 是 2.55.0.5(尚未含随包 wincred),用户自己配的 host-scoped gh auth git-credential 照常生效;下一版随包提供 git 自带的 git-credential-wincred.exe(172 KB,读 Windows 凭据管理器里同名的 git:<proto>://<host> 条目),但不会写进系统 gitconfig 当默认(避免排在用户自己的 helper 之前)。

    迁移(重要前置)

    layout: flat 需要 WinuxCmd/wpm ≥ 1.1.9(旧 wpm 会用裸 DeleteFileW 去断 usr\bin 多调用硬链接 → 自锁、报 failed to break WinuxCmd hardlink ... Access denied):

    wpm update winuxcmd
    wpm install niugit --force
    

    后续(另开范围,不阻塞本票)

    已在 CI 里就绪、下一次发布带上:wincred helper、版本标识(git --version 现在会带 2.56.0.windows.2.niugit,之前是裸 2.55.0)、/pathmap+/Brepro 可复现且不泄露构建路径、裁掉 bin/ 里的 dashed 形式、补齐此前漏发的 libexpat.dll(git http-push 之前会在用户机上起不来),以及 2.56.0.windows.2 上游基线 + ARM64 产物(CI 已能双架构构建,并会自动更新 wpm 索引的 windows-x64/windows-arm64)。

    验证环境:本机 winuxcmd 1.1.9 + niugit 2.55.0.5(wpm 安装,flat),Intel x64。

  4. caomengxuan666 commented on Oct 16, 2026

    @caomengxuan666
    MemberAuthor

    Adding a measurement for the fix direction, since the issue is about launcher cost.

    Hardlink vs forwarding wrapper

    Same machine, same repo state, Python subprocess timing, warm cache, parent is a native process, N=20 after 3 warmups:

    git --version avg min
    payload ...\winuxcmd\opt\niugit\mingw64\bin\git.exe 13.1 11.2
    hardlink ...\winuxcmd\usr\bin\git.exe 12.8 11.0
    hardlink ...\winuxcmd\bin\git.exe (new directory) 12.7 10.5
    forwarding git.cmd that execs usr\bin\git.exe 32.2 29.5

    A hardlink costs nothing: 12.7 ms against the payload's 13.1 ms is noise. A forwarding wrapper costs a full process, 19.4 ms, which lands it in the same band as the Git for Windows cmd\git.exe launcher (38.7 ms in the same run).

    The link is location-independent

    A link placed in a different directory still self-locates, so patch #3's upward marker probe is not tied to usr\bin:

    C:\...\winuxcmd\bin\git.exe --version            -> git version 2.55.0
    C:\...\winuxcmd\bin\git.exe --exec-path          -> C:/.../winuxcmd/opt/niugit/mingw64/libexec/git-core
    C:\...\winuxcmd\bin\git.exe config --system --list -> http.sslbackend=schannel
    C:\...\winuxcmd\bin\git.exe --html-path          -> C:/.../winuxcmd/opt/niugit/mingw64/share/doc/git-doc
    

    End-to-end in a real repository (3,942 entries, 30+ worktrees): status --porcelain, log -1, rev-parse --show-toplevel, and submodule status (which needs sh) all behave.

    Caveat that belongs in this issue

    A hardlink only helps if something refreshes it. On this machine the live inode is shared by .wpm/staging/niugit/mingw64/bin/git.exe, usr\bin\git.exe and bin\git.exe, while opt/niugit/mingw64/bin/git.exe is a second, separate 5.2 MB file, even though the wpm manifest declares opt/niugit/... as the payload. Any update that replaces one path by unlink-plus-create leaves the PATH-visible link serving the old bytes. Filed against WinuxCmd; the same refresh requirement applies to whatever mechanism this issue settles on.

    Suggestion

    Keep the entry point a hardlink to the real binary. If a launcher is needed for environment setup, resolve that in-process (argv[0] dispatch, as proposed for sh/bash) rather than by spawning a second executable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions