From 4e21041d2ccead2033250dc8fe64a8b2438fcfd1 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Tue, 14 Apr 2026 00:57:10 +0200 Subject: [PATCH] perf: skip store integrity verification by calling readPkgFromCafs directly The wrapped fetchPackage now calls readPkgFromCafs with verifyStoreIntegrity: false instead of going through the real fetchPackage (which has verifyStoreIntegrity baked in at creation time). This skips stat + hash checks for all 33K files that were just written by the agent. --- .../deps-installer/src/install/index.ts | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/installing/deps-installer/src/install/index.ts b/installing/deps-installer/src/install/index.ts index 9fe2682d4a..8d4087d8d7 100644 --- a/installing/deps-installer/src/install/index.ts +++ b/installing/deps-installer/src/install/index.ts @@ -1902,13 +1902,34 @@ async function installFromPnpmRegistry ( prefix: rootDir, }) - // Wrap the store controller so fetchPackage waits for file downloads - // before checking the store. This prevents npm fallback — headless - // install blocks until the files are written, then finds them in CAFS. + // Wrap fetchPackage to: + // 1. Wait for agent file downloads before checking the store + // 2. Skip integrity verification — files just written from the agent + // are guaranteed correct (server verified, no rehashing needed) + const { readPkgFromCafs } = await import('@pnpm/worker') + const { storeIndexKey: _storeIndexKey } = await import('@pnpm/store.index') const wrappedStoreController = { ...opts.storeController, fetchPackage: async (fetchOpts: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any await fileDownloads + const resolution = fetchOpts.pkg.resolution + const integrity = resolution?.integrity + if (integrity) { + const filesIndexFile = _storeIndexKey(integrity, fetchOpts.pkg.id) + const result = await readPkgFromCafs( + { storeDir: opts.storeDir, verifyStoreIntegrity: false }, + filesIndexFile, + { readManifest: true, expectedPkg: { name: fetchOpts.pkg.name, version: fetchOpts.pkg.version } } + ) + return { + fetching: () => Promise.resolve({ + files: result.files, + bundledManifest: result.bundledManifest, + integrity, + }), + filesIndexFile, + } + } return opts.storeController.fetchPackage(fetchOpts) }, }