Skip to content

Commit 9287251

Browse files
arcanismerceyz
andauthored
Perf work (#5740)
**What's the problem this PR addresses?** This diff implements a couple of small performance improvements. **How did you fix it?** - Removed `nodeUtils.builtinModules` (use `module.builtinModules`) - Optimized some `ppath` functions on non-win32 platforms - Removed `toFilename` (just cast to `Filename` if needed) - The `yarnPath` same-file check now uses inodes on non-win32 platforms - Hoisted a couple of regexps to avoid re-instantiations | Command | Mean [ms] | Min [ms] | Max [ms] | Relative | |:---|---:|---:|---:|---:| | `before` | 236.5 ± 2.7 | 233.2 | 241.0 | 1.06 ± 0.02 | | `after` | 222.7 ± 3.2 | 219.6 | 230.7 | 1.00 | **Checklist** <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed. --------- Co-authored-by: Kristoffer K. <[email protected]>
1 parent 8748f5f commit 9287251

File tree

22 files changed

+266
-207
lines changed

22 files changed

+266
-207
lines changed

.pnp.cjs

+20-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.pnp.loader.mjs

+18-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.yarn/versions/0aa36442.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
releases:
2+
"@yarnpkg/cli": major
3+
"@yarnpkg/core": major
4+
"@yarnpkg/fslib": major
5+
"@yarnpkg/nm": major
6+
"@yarnpkg/plugin-nm": major
7+
"@yarnpkg/plugin-npm": major
8+
"@yarnpkg/pnp": major
9+
"@yarnpkg/pnpify": major
10+
11+
declined:
12+
- "@yarnpkg/plugin-compat"
13+
- "@yarnpkg/plugin-constraints"
14+
- "@yarnpkg/plugin-dlx"
15+
- "@yarnpkg/plugin-essentials"
16+
- "@yarnpkg/plugin-exec"
17+
- "@yarnpkg/plugin-file"
18+
- "@yarnpkg/plugin-git"
19+
- "@yarnpkg/plugin-github"
20+
- "@yarnpkg/plugin-http"
21+
- "@yarnpkg/plugin-init"
22+
- "@yarnpkg/plugin-interactive-tools"
23+
- "@yarnpkg/plugin-link"
24+
- "@yarnpkg/plugin-npm-cli"
25+
- "@yarnpkg/plugin-pack"
26+
- "@yarnpkg/plugin-patch"
27+
- "@yarnpkg/plugin-pnp"
28+
- "@yarnpkg/plugin-pnpm"
29+
- "@yarnpkg/plugin-stage"
30+
- "@yarnpkg/plugin-typescript"
31+
- "@yarnpkg/plugin-version"
32+
- "@yarnpkg/plugin-workspace-tools"
33+
- vscode-zipfs
34+
- "@yarnpkg/builder"
35+
- "@yarnpkg/doctor"
36+
- "@yarnpkg/extensions"
37+
- "@yarnpkg/libzip"
38+
- "@yarnpkg/sdks"
39+
- "@yarnpkg/shell"

packages/acceptance-tests/pkg-tests-core/sources/utils/tests.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import {miscUtils, semverUtils} from '@yarnpkg/core';
2-
import {PortablePath, npath, toFilename, xfs, ppath, Filename} from '@yarnpkg/fslib';
3-
import {npmAuditTypes} from '@yarnpkg/plugin-npm-cli';
4-
import assert from 'assert';
5-
import crypto from 'crypto';
6-
import finalhandler from 'finalhandler';
7-
import https from 'https';
8-
import {IncomingMessage, ServerResponse} from 'http';
9-
import http from 'http';
10-
import invariant from 'invariant';
11-
import {AddressInfo} from 'net';
12-
import os from 'os';
13-
import pem from 'pem';
14-
import semver from 'semver';
15-
import serveStatic from 'serve-static';
16-
import stream from 'stream';
17-
import * as t from 'typanion';
18-
import {promisify} from 'util';
19-
import {v5 as uuidv5} from 'uuid';
20-
import {Gzip} from 'zlib';
21-
22-
import {ExecResult} from './exec';
23-
import * as fsUtils from './fs';
1+
import {miscUtils, semverUtils} from '@yarnpkg/core';
2+
import {PortablePath, npath, xfs, ppath, Filename} from '@yarnpkg/fslib';
3+
import {npmAuditTypes} from '@yarnpkg/plugin-npm-cli';
4+
import assert from 'assert';
5+
import crypto from 'crypto';
6+
import finalhandler from 'finalhandler';
7+
import https from 'https';
8+
import {IncomingMessage, ServerResponse} from 'http';
9+
import http from 'http';
10+
import invariant from 'invariant';
11+
import {AddressInfo} from 'net';
12+
import os from 'os';
13+
import pem from 'pem';
14+
import semver from 'semver';
15+
import serveStatic from 'serve-static';
16+
import stream from 'stream';
17+
import * as t from 'typanion';
18+
import {promisify} from 'util';
19+
import {v5 as uuidv5} from 'uuid';
20+
import {Gzip} from 'zlib';
21+
22+
import {ExecResult} from './exec';
23+
import * as fsUtils from './fs';
2424

2525
const deepResolve = require(`super-resolve`);
2626
const staticServer = serveStatic(npath.fromPortablePath(require(`pkg-tests-fixtures`)));
@@ -257,7 +257,7 @@ export const getPackageArchivePath = async (name: string, version: string): Prom
257257
throw new Error(`Unknown version "${version}" for package "${name}"`);
258258

259259
const tmpDir = await xfs.mktempPromise();
260-
const archivePath = `${tmpDir}/${toFilename(`${name}-${version}.tar.gz`)}` as PortablePath;
260+
const archivePath = ppath.join(tmpDir, `${name}-${version}.tar.gz`);
261261

262262
await fsUtils.packToFile(archivePath, npath.toPortablePath(packageVersionEntry.path), {
263263
virtualPath: npath.toPortablePath(`/package`),

packages/plugin-nm/sources/NodeModulesLinker.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Locator, Package, FinalizeInstallStatus, hashUtils} from
33
import {Linker, LinkOptions, MinimalLinkOptions, LinkType, WindowsLinkType} from '@yarnpkg/core';
44
import {LocatorHash, Descriptor, DependencyMeta, Configuration} from '@yarnpkg/core';
55
import {MessageName, Project, FetchResult, Installer} from '@yarnpkg/core';
6-
import {PortablePath, npath, ppath, toFilename, Filename} from '@yarnpkg/fslib';
6+
import {PortablePath, npath, ppath, Filename} from '@yarnpkg/fslib';
77
import {VirtualFS, xfs, FakeFS, NativePath} from '@yarnpkg/fslib';
88
import {ZipOpenFS} from '@yarnpkg/libzip';
99
import {buildNodeModulesTree} from '@yarnpkg/nm';
@@ -493,7 +493,7 @@ async function findInstallState(project: Project, {unrollAliases = false}: {unro
493493
const location = ppath.join(rootPath, npath.toPortablePath(relativeLocation));
494494
const symlinks = miscUtils.getMapWithDefault(binSymlinks, location);
495495
for (const [name, target] of Object.entries(locationSymlinks as any)) {
496-
symlinks.set(toFilename(name), npath.toPortablePath([location, NODE_MODULES, target].join(ppath.sep)));
496+
symlinks.set(name as Filename, npath.toPortablePath([location, NODE_MODULES, target].join(ppath.sep)));
497497
}
498498
}
499499
}
@@ -540,7 +540,7 @@ const removeDir = async (dir: PortablePath, options: {contentsOnly: boolean, inn
540540
}
541541
const entries = await xfs.readdirPromise(dir, {withFileTypes: true});
542542
for (const entry of entries) {
543-
const targetPath = ppath.join(dir, toFilename(entry.name));
543+
const targetPath = ppath.join(dir, entry.name);
544544
if (entry.isDirectory()) {
545545
if (entry.name !== NODE_MODULES || (options && options.innerLoop)) {
546546
await removeDir(targetPath, {innerLoop: true, contentsOnly: false});
@@ -688,7 +688,7 @@ const symlinkPromise = async (srcPath: PortablePath, dstPath: PortablePath, wind
688688
};
689689

690690
async function atomicFileWrite(tmpDir: PortablePath, dstPath: PortablePath, content: Buffer) {
691-
const tmpPath = ppath.join(tmpDir, toFilename(`${crypto.randomBytes(16).toString(`hex`)}.tmp`));
691+
const tmpPath = ppath.join(tmpDir, `${crypto.randomBytes(16).toString(`hex`)}.tmp`);
692692
try {
693693
await xfs.writeFilePromise(tmpPath, content);
694694
try {
@@ -713,7 +713,7 @@ async function copyFilePromise({srcPath, dstPath, entry, globalHardlinksStore, b
713713
const contentDigest = await hashUtils.checksumFile(contentFilePath, {baseFs: xfs, algorithm: `sha1`});
714714
if (contentDigest !== entry.digest) {
715715
// If file content was modified by the user, or corrupted, we first move it out of the way
716-
const tmpPath = ppath.join(globalHardlinksStore, toFilename(`${crypto.randomBytes(16).toString(`hex`)}.tmp`));
716+
const tmpPath = ppath.join(globalHardlinksStore, `${crypto.randomBytes(16).toString(`hex`)}.tmp`);
717717
await xfs.renamePromise(contentFilePath, tmpPath);
718718

719719
// Then we overwrite the temporary file, thus restorting content of original file in all the linked projects
@@ -997,7 +997,7 @@ async function createBinSymlinkMap(installState: NodeModulesLocatorMap, location
997997
const binScripts = locatorScriptMap.get(node.locator)!;
998998
for (const [filename, scriptPath] of binScripts) {
999999
const symlinkTarget = ppath.join(location, npath.toPortablePath(scriptPath));
1000-
symlinks.set(toFilename(filename), symlinkTarget);
1000+
symlinks.set(filename, symlinkTarget);
10011001
}
10021002
for (const [childLocation, childNode] of node.children) {
10031003
const absChildLocation = ppath.join(location, childLocation);
@@ -1349,7 +1349,7 @@ async function persistBinSymlinks(previousBinSymlinks: BinSymlinkMap, binSymlink
13491349
// Remove outdated symlinks
13501350
await xfs.removePromise(ppath.join(binDir, name));
13511351
if (process.platform === `win32`) {
1352-
await xfs.removePromise(ppath.join(binDir, toFilename(`${name}.cmd`)));
1352+
await xfs.removePromise(ppath.join(binDir, `${name}.cmd`));
13531353
}
13541354
}
13551355
}

0 commit comments

Comments
 (0)