Skip to content

perf: extract packages in a worker pool#6850

Merged
zkochan merged 3 commits intomainfrom
worker-pool
Aug 13, 2023
Merged

perf: extract packages in a worker pool#6850
zkochan merged 3 commits intomainfrom
worker-pool

Conversation

@zkochan
Copy link
Copy Markdown
Member

@zkochan zkochan commented Jul 23, 2023

previous PR: #6819

@zkochan
Copy link
Copy Markdown
Member Author

zkochan commented Aug 5, 2023

@dmichon-msft do you see obvious issues with these changes? These make pnpm slower at least 2 times.

Copy link
Copy Markdown
Contributor

@dmichon-msft dmichon-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd need to see a CPU profile to know for sure, but this sounds like thread contention issues.

Comment thread fetching/tarball-fetcher/src/remoteTarballFetcher.ts Outdated
Comment thread fetching/tarball-fetcher/src/worker/tarballWorker.ts Outdated
Comment thread fetching/tarball-fetcher/src/index.ts Outdated
@zkochan
Copy link
Copy Markdown
Member Author

zkochan commented Aug 8, 2023

Thanks for the suggestions. I did some of the suggested changes and now the performance seems to be the same as without the changes.

I still need to do the gunzip changes.

@zkochan
Copy link
Copy Markdown
Member Author

zkochan commented Aug 8, 2023

OK, I did sync extraction too and some more benchmarks. It looks like, when the lockfile is up to date (so no resolution needs to happen) these optimizations actually make install about 33% faster. This is a great improvement.

When there is no lockfile, the performance is almost the same because resolution of the lockfile is a bottleneck.

Comment thread store/cafs/src/writeBufferToCafs.ts Outdated
Base automatically changed from fetch-perf to main August 8, 2023 22:41
@zkochan zkochan changed the title perf: extract package in worker pool perf: extract packages in a worker pool Aug 8, 2023
Comment thread fetching/tarball-fetcher/src/index.ts Outdated
workerScriptPath: path.join(__dirname, 'worker/tarballWorker.js'),
})
// @ts-expect-error
global.finishWorkers = () => workerPool.finishAsync()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a hack. For now it should be fine as I want to minimize the changes in this PR but in the future we'll have to find a better solution to call this function.

@zkochan zkochan marked this pull request as ready for review August 13, 2023 12:14
@zkochan zkochan requested a review from a team August 13, 2023 13:40
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are this changes expected? (The workspace:* to versions) I tried to pull this PR to test it and every command fails with this error

✘ [ERROR] No matching export in "../../../Users/nacho/Documents/code/pnpm/fetching/tarball-fetcher/src/index.ts" for import "waitForFilesIndex"

    ../../../Users/nacho/Documents/code/pnpm/env/node.fetcher/src/index.ts:11:31:
      11 │ import { createTarballFetcher, waitForFilesIndex } from '@pnpm/tarball-fetcher'~~~~~~~~~~~~~~~~~

/Users/nacho/Documents/code/pnpm/node_modules/.pnpm/esbuild@0.18.17/node_modules/esbuild/lib/main.js:1649
  let error = new Error(`${text}${summary}`);
              ^

Error: Build failed with 1 error:
../../../Users/nacho/Documents/code/pnpm/env/node.fetcher/src/index.ts:11:31: ERROR: No matching export in "../../../Users/nacho/Documents/code/pnpm/fetching/tarball-fetcher/src/index.ts" for import "waitForFilesIndex"
    at failureErrorWithLog (/Users/nacho/Documents/code/pnpm/node_modules/.pnpm/esbuild@0.18.17/node_modules/esbuild/lib/main.js:1649:15)
    at /Users/nacho/Documents/code/pnpm/node_modules/.pnpm/esbuild@0.18.17/node_modules/esbuild/lib/main.js:1058:25
    at runOnEndCallbacks (/Users/nacho/Documents/code/pnpm/node_modules/.pnpm/esbuild@0.18.17/node_modules/esbuild/lib/main.js:1484:45)
    at buildResponseToResult (/Users/nacho/Documents/code/pnpm/node_modules/.pnpm/esbuild@0.18.17/node_modules/esbuild/lib/main.js:1056:7)
    at /Users/nacho/Documents/code/pnpm/node_modules/.pnpm/esbuild@0.18.17/node_modules/esbuild/lib/main.js:1085:16
    at responseCallbacks.<computed> (/Users/nacho/Documents/code/pnpm/node_modules/.pnpm/esbuild@0.18.17/node_modules/esbuild/lib/main.js:703:9)
    at handleIncomingPacket (/Users/nacho/Documents/code/pnpm/node_modules/.pnpm/esbuild@0.18.17/node_modules/esbuild/lib/main.js:762:9)
    at Socket.readFromStdout (/Users/nacho/Documents/code/pnpm/node_modules/.pnpm/esbuild@0.18.17/node_modules/esbuild/lib/main.js:679:7)
    at Socket.emit (node:events:514:28)
    at addChunk (node:internal/streams/readable:343:12) {
  errors: [
    {
      detail: undefined,
      id: '',
      location: {
        column: 31,
        file: '../../../Users/nacho/Documents/code/pnpm/env/node.fetcher/src/index.ts',
        length: 17,
        line: 11,
        lineText: "import { createTarballFetcher, waitForFilesIndex } from '@pnpm/tarball-fetcher'",
        namespace: '',
        suggestion: ''
      },
      notes: [],
      pluginName: '',
      text: 'No matching export in "../../../Users/nacho/Documents/code/pnpm/fetching/tarball-fetcher/src/index.ts" for import "waitForFilesIndex"'
    }
  ],
  warnings: []
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you run pnpm install?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the weird thing is that I can go to the waitForFilesIndex import in Vscode

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why. Try

git clean -fdx
pnpm install

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't work, I removed my local repo to start from scratch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't work either, I also tried in a codespace and it fails too, same error

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But on github actions it works.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed by #6938

@zkochan
Copy link
Copy Markdown
Member Author

zkochan commented Aug 13, 2023

I will merge these soon but I will not release the changes as stable yet. For now, it will be released under a prerelease version.

@zkochan zkochan merged commit 083bbf5 into main Aug 13, 2023
@zkochan zkochan deleted the worker-pool branch August 13, 2023 23:07
zkochan added a commit that referenced this pull request Aug 14, 2023
@gluxon
Copy link
Copy Markdown
Member

gluxon commented Aug 17, 2023

Excited for the perf improvements here!

wbinnssmith added a commit to vercel/turborepo that referenced this pull request Sep 1, 2023
To go along with vercel/next.js#54873

Includes pnpm/pnpm#6850, which improves installation performance.
wbinnssmith added a commit to vercel/turborepo that referenced this pull request Sep 6, 2023
To go along with vercel/next.js#54873

Includes pnpm/pnpm#6850, which improves
installation performance.


Closes WEB-1493
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.

4 participants