Repository navigation
perf(wpm): a small forwarder for layout: shim packages (-12.4 ms per call) - #1217
Merged
Merged
Conversation
caomengxuan666
force-pushed
the
feat/package-shim-forwarder
branch
2 times, most recently
from
October 17, 2026 07:23
728c5ea to
15528cf
Compare
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).
caomengxuan666
force-pushed
the
feat/package-shim-forwarder
branch
from
October 17, 2026 07:25
15528cf to
f139265
Compare
This was referenced Oct 17, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: shimcommand —python,node,curl,openssl,ssh*,gawk— is a hardlink to an olderwinuxcmd.exewhose only job is to spawnopt\<pkg>\<command>.exeand wait. Verified by content:usr\bin\python.exe/node.exe/curl.exe/openssl.exeare byte-identical to.wpm\backup\winuxcmd-before-update-11668.exe, thessh*/gawkgroup 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):
winuxcmd.exewinuxcmd-shim.exe12.4 ms saved per invocation, on every
python/node/curl/ssh/npmcall 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 intousr/bin/winuxcmd-shim.exenext towinuxcmd.exe.Two deliberate details:
GetCommandLineW(). Nothing is re-quoted: re-quoting is exactly how a forwarder corrupts arguments (the class of bug behind niu-git • feat: add head/tail/find/grep/cut/which/env and doc updates #3/feat(Command):Add new command,optimize and fix command bugs. - sed is now supported. - Fix up cut bugs. - grep optimize,more args support. - which is more strong. #4), and the rule is the one the shell already follows.STARTF_USESTDHANDLES) and the child isDETACHED_PROCESSwhen none of our streams is a console. A detached child gets no standard handles by default — without this its output goes nowhere and only its exit code arrives, which is how the first build of this behaved.wpm side
create_package_shimslinks 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 --forceadditionally 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
"inside an argument, trailing\, an empty argument,C:\path\,nested"quote\,--/-x/*.exit 7→ 7), stderr, stdin (5 bytes read by the payload).no payload is registered for '<cmd>'and exits 127.wpm.shim_packages_use_the_forwarder_when_present— installs a shim package without the forwarder (link towinuxcmd.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, sowinuxcmd-shim.exetravels with the next release — but the wpm-sourcefilesmapping must gain that entry, otherwisewpm update winuxcmdinstalls the exe without recording it. I will open that PR once the release carrying the exe exists, and note it in #1207.