Repository navigation
build: stop paying for an npm install and a skills fetch on every make install - #568
Merged
Merged
Conversation
…e install Two steps of `make install` ran unconditionally even when nothing needed them. npm install: the Makefile branched per platform here — POSIX compared manifest mtimes against the npm install stamp, while Windows ran `npm install` every time because cmd/make has no usable mtime test. Measured on Windows, a no-op `npm install --silent` is 6-13s of a ~13s steady-state `make install`. scripts/npm-install-if-needed.mjs now does that check for both platforms: it expands the root `workspaces` globs, compares every manifest against `node_modules/.package-lock.json` (the stamp npm itself writes), and installs only when one is newer or the stamp is missing. The skip costs one Node start (~0.07s). The script goes through cmd.exe explicitly on Windows — npm is npm.cmd, which Node refuses to spawn without a shell, and shell:true plus arguments is deprecated. skills: `install-skills` passed `--remote` to `git submodule update`, so every install hit the network for a submodule fetch (2.6s of the 3.2s step). `install` now uses the commits already checked out and works offline; `make update-skills` keeps the refresh-from-remote behaviour and is listed in `make help`. Verified with a scratch-tree probe of the four decision paths: missing stamp installs, unchanged tree skips, a bumped workspace manifest installs, and a manifest with a UTF-8 BOM is parsed rather than crashing (npm tolerates the BOM, JSON.parse does not).
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.
Problem
After the dist-mtime fix (#566), a steady-state
make installon Windows was ~13s, and two of its steps ran unconditionally even when nothing needed them:npm install--remotefetch + copy)npm install: the Makefile branched per platform for this. POSIX compared manifest mtimes against npm's install stamp; Windows ran
npm installevery time, because cmd/make has no usable mtime test. Measured directly, a no-opnpm install --silentcosts 6-13s here.skills:
install-skillspassed--remotetogit submodule update, so every install did a network fetch. Measured:git submodule update --init skillsis 0.6s, adding--remotemakes it 2.6s, and the whole step was 3.2s.Fix
scripts/npm-install-if-needed.mjsnow does the staleness check for both platforms: it expands the rootworkspacesglobs, compares every manifest (package.json,package-lock.json, each workspace manifest) againstnode_modules/.package-lock.json— the stamp npm itself writes — and installs only when one is newer or the stamp is missing. Skipping costs one Node start (~0.07s).Two details worth noting:
npm.cmd, which Node refuses to spawn without a shell (CVE-2024-27980 hardening), whileshell: truecombined with arguments triggersDEP0190. The script therefore invokescmd.exeexplicitly with a fixed command string — verified with no deprecation warning.package.json(Windows editors add them),JSON.parsedoes not, and this check runs on every build — a BOM would have brokenmake installrather than the install it guards.install-skillsno longer passes--remote, somake installuses the submodule commits already checked out and works offline.make update-skillskeeps the refresh-from-remote behaviour (the only skills step that needs the network) and is listed inmake help.Verification
Decision logic, probed in a scratch tree with a copy of the script:
npm install (workspace manifests changed)packages/a/package.jsonbumped after the stampnpm install (workspace manifests changed)package.jsonwith a UTF-8 BOMnpm install (workspace manifests changed)The
workspacesglob expansion is what case 3 exercises (packages/*→packages/a/package.json); adesktop/mobilemanifest is checked the same way.End-to-end
make installnumbers on this machine are in the PR comments below.