Skip to content

perf(wpm): a small forwarder for layout: shim packages (-12.4 ms per call) - #1217

Merged
caomengxuan666 merged 1 commit into
mainfrom
feat/package-shim-forwarder
Oct 17, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
feat/package-shim-forwarder

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Implements #1207 (the measurement and the two gaps are in that issue; the index mapping is the follow-up below).

What the hop costs today

A layout: shim command — python, node, curl, openssl, ssh*, gawk — is a hardlink to an older winuxcmd.exe whose only job is to spawn opt\<pkg>\<command>.exe and wait. Verified by content: usr\bin\python.exe / node.exe / curl.exe / openssl.exe are byte-identical to .wpm\backup\winuxcmd-before-update-11668.exe, the ssh*/gawk group to …-12268.exe. So every invocation pays a whole WinuxCmd startup.

Measured here on the hop alone (three interleaved rounds of 15, medians of medians, one heavy payload for the old side and a cheap one for the new — see the method note in #1207):

dispatch hop
old: link to winuxcmd.exe 24.5 ms
new: winuxcmd-shim.exe 12.1 ms

12.4 ms saved per invocation, on every python/node/curl/ssh/npm call an agent, a git hook or CI makes.

The forwarder

src/shims/winuxcmd_shim.cpp — reads .wpm\shims.map (<command>=<payload relative to the installation root>), starts the payload, forwards stdio and the exit code. Nothing but the C runtime; it is built into usr/bin/winuxcmd-shim.exe next to winuxcmd.exe.

Two deliberate details:

wpm side

  • create_package_shims links a shim to the forwarder when the installation has one; without it the previous behaviour is unchanged, so an older root keeps working.
  • wpm links rebuild --force additionally refreshes mapped package shims, and activation already runs it at shell start — so an existing install picks up the cheaper dispatch without reinstalling packages.

Verification

  • Argument fidelity: 5/5 adversarial cases byte-identical to a direct payload call — plain args, embedded space/tab, " inside an argument, trailing \, an empty argument, C:\path\, nested"quote\, --/-x/*.
  • Pass-through: exit code (exit 7 → 7), stderr, stdin (5 bytes read by the payload).
  • Unregistered command: reports no payload is registered for '<cmd>' and exits 127.
  • Test: wpm.shim_packages_use_the_forwarder_when_present — installs a shim package without the forwarder (link to winuxcmd.exe, no map) and then with it (link to the forwarder, map names the payload). wpm.* green; full suite 2896/2898 with the two known machine-local i18n failures.

Follow-up (not this PR)

The release artifact is assembled from usr/bin, so winuxcmd-shim.exe travels with the next release — but the wpm-source files mapping must gain that entry, otherwise wpm update winuxcmd installs the exe without recording it. I will open that PR once the release carrying the exe exists, and note it in #1207.

@caomengxuan666
caomengxuan666 force-pushed the feat/package-shim-forwarder branch 2 times, most recently from 728c5ea to 15528cf Compare October 17, 2026 07:23
A shim-layout command (`python`, `node`, `curl`, `openssl`, `ssh*`, `gawk`) was a
hardlink to an older `winuxcmd.exe` whose only job was to spawn
`opt\<pkg>\<command>.exe` and wait, so every invocation paid a whole WinuxCmd
startup. Measured here on the dispatcher hop alone (median of three interleaved
rounds, 15 runs each, cheap and heavy payloads both):

  old dispatcher (winuxcmd.exe link): 24.5 ms
  new forwarder (winuxcmd-shim.exe):  12.1 ms
  -> 12.4 ms saved per invocation

- `src/shims/winuxcmd_shim.cpp` is that forwarder: it reads `.wpm\shims.map`
  (`<command>=<payload relative to the installation root>`), starts the payload,
  forwards stdio and the exit code. It depends on nothing but the C runtime, and
  it splices arguments **verbatim** out of `GetCommandLineW()` - re-quoting is how
  a forwarder corrupts them, and the rule is the one the shell already follows.
- wpm points a shim at the forwarder **when the installation has one**; without
  it the previous behaviour is unchanged, so an older root keeps working.
  `wpm links rebuild --force` (which activation already runs) also refreshes
  mapped package shims, so existing installs pick the cheaper dispatch up on the
  next shell start instead of needing every package reinstalled.
- The payload keeps its private DLLs beside itself in `opt\`, never in a
  directory on `%PATH%` - the reason the shim layout exists at all.

Verified: arguments round-trip byte-identically against a direct payload call for
five adversarial cases (quotes, trailing backslashes, empty argument, tabs,
`C:\` paths); exit code, stdin and stderr pass through; an unregistered command
reports itself and exits 127. Test
`wpm.shim_packages_use_the_forwarder_when_present` covers both wirings.

Shipping: the release artifact is assembled from `usr/bin`, so
`winuxcmd-shim.exe` travels with it; the wpm-source `files` mapping must gain the
entry for an update to install it (follow-up to #1207).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant