Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(pkgs-graph): speed up createPkgGraph when directory specifiers are present #6317

Merged
merged 2 commits into from Mar 29, 2023

Conversation

jakebailey
Copy link
Member

This speeds up the install of "with paths" test case (https://github.com/jakebailey/DefinitelyTyped/tree/blog-pnpm-workspaces-with-paths) from 49.7s to 14s.

Time spent in createPkgMap has been reduced from ~35s to ~200ms, matching the performance in #6287.

Fixes #6281 (for real this time)

function getPkgMapByDir (pkgMapValues: Package[]) {
const pkgMapByDir: Record<string, Package | undefined> = {}
for (const pkg of pkgMapValues) {
pkgMapByDir[path.resolve(pkg.dir)] = pkg
Copy link
Member Author

Choose a reason for hiding this comment

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

This resolve is defensive; since we're comparing resolved paths above, I wanted to ensure everything went through this algorithm before comparison. It's possible that this is not needed, however, there doesn't seem to be any negative performance hit.

@jakebailey
Copy link
Member Author

Clearly I celebrated too early; Windows seems to be misbehaving. I'll take a look.

@jakebailey
Copy link
Member Author

Hm, seems like a spurious failure; I just reran it and it passed.

@zkochan
Copy link
Member

zkochan commented Mar 29, 2023

Unfortunately there are one or two unstable tests. Especially on Windows.

return found.dir
}

// Slow path; only needed when there are case mismatches on case-insensitive filesystems.
Copy link
Member

Choose a reason for hiding this comment

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

In theory we could detect whether it is a case-insensitive fs. In a future optimization. I already use this lib for detecting case sensitive dirs: https://github.com/zkochan/packages/tree/main/dir-is-case-sensitive

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's a good idea. Another related optimization would be to ensure that all paths are "resolved", that way all of the path checks can skip re-resolving and instead use plain comparison and path.join + path.normalize.

@zkochan zkochan merged commit 9fd0e37 into pnpm:main Mar 29, 2023
8 checks passed
@jakebailey jakebailey deleted the perf-createPkgGraph-paths branch March 29, 2023 20:18
zkochan pushed a commit that referenced this pull request Mar 29, 2023
…re present (#6317)

* perf(pkgs-graph): speed up createPkgGraph when directory specifiers are present

* perf(pkgs-graph): make pkgMapByManifestName equally lazy
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.

None yet

2 participants