From d65a383decb8f34cd1483aa4fffbe4c09164ecb8 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 6 May 2026 09:56:32 +0200 Subject: [PATCH] perf(package-requester): gate the upgrade-path SQLite probe on cheap checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The migration block that copies a git-hosted tarball entry from the legacy gitHostedStoreIndexKey to storeIndexKey(integrity, pkgId) was calling storeIndex.has() on every fetch, including all npm-registry packages it has no business probing — a SELECT per package, multiplied across thousands of dependencies. Reorder so the URL prefix check (isGitHostedPkgUrl) and the integrity presence check run first, and the SQLite lookup only runs for git-hosted resolutions with integrity in the lockfile. Same migration behaviour, ~zero overhead on the hot path. --- Written by an agent (Claude Code, claude-opus-4-7). --- .../package-requester/src/packageRequester.ts | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/installing/package-requester/src/packageRequester.ts b/installing/package-requester/src/packageRequester.ts index 1ee6306792..c77bc4025b 100644 --- a/installing/package-requester/src/packageRequester.ts +++ b/installing/package-requester/src/packageRequester.ts @@ -526,22 +526,22 @@ function fetchToStore ( // Once v12 forces lockfile regeneration, every store keyed by the new // pnpm will already have the integrity-keyed entry and this lookup is // dead code. + // + // Cheap string checks (URL prefix, integrity present) gate the SQLite + // existence lookup so we only probe storeIndex for git-hosted packages. + const tarballUrl = (opts.pkg.resolution as TarballResolution).tarball if ( !opts.force && ctx.storeIndex != null && + tarballUrl != null && + (opts.pkg.resolution as TarballResolution).integrity && + isGitHostedPkgUrl(tarballUrl) && !ctx.storeIndex.has(filesIndexFile) ) { - const tarballUrl = (opts.pkg.resolution as TarballResolution).tarball - if ( - tarballUrl != null && - isGitHostedPkgUrl(tarballUrl) && - (opts.pkg.resolution as TarballResolution).integrity - ) { - const legacyKey = gitHostedStoreIndexKey(opts.pkg.id, { built: !opts.ignoreScripts }) - const legacyData = ctx.storeIndex.getRaw(legacyKey) - if (legacyData) { - ctx.storeIndex.setRawMany([{ key: filesIndexFile, buffer: legacyData }]) - } + const legacyKey = gitHostedStoreIndexKey(opts.pkg.id, { built: !opts.ignoreScripts }) + const legacyData = ctx.storeIndex.getRaw(legacyKey) + if (legacyData) { + ctx.storeIndex.setRawMany([{ key: filesIndexFile, buffer: legacyData }]) } }