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

Improve pnp loader speed and memory: jszip implementation #6688

Merged
merged 12 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
723 changes: 496 additions & 227 deletions .pnp.cjs

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions .yarn/versions/01575767.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
releases:
"@yarnpkg/cli": minor
"@yarnpkg/libzip": minor
"@yarnpkg/plugin-pnp": minor
"@yarnpkg/pnp": minor

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
- "@yarnpkg/fslib"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ immutablePatterns:

initScope: yarnpkg

pnpZipBackend: js

npmPublishAccess: public

packageExtensions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const {

const configs = [{
nodeLinker: `pnp`,
}, {
nodeLinker: `pnp`,
pnpZipBackend: `js`,
}, {
nodeLinker: `pnpm`,
}, {
Expand All @@ -13,7 +16,7 @@ const configs = [{

describe(`Basic tests`, () => {
for (const config of configs) {
describe(`w/ the ${config.nodeLinker} linker`, () => {
describe(`w/ the ${config.nodeLinker} linker${config.pnpZipBackend ? ` and ${config.pnpZipBackend} zip backend` : ``}`, () => {
test(
`it should correctly handle browser fields in package.json`,
makeTemporaryEnv(
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-pnp/sources/PnpLinker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ export class PnpInstaller implements Installer {
const ignorePattern = miscUtils.buildIgnorePattern([`.yarn/sdks/**`, ...this.opts.project.configuration.get(`pnpIgnorePatterns`)]);
const packageRegistry = this.packageRegistry;
const shebang = this.opts.project.configuration.get(`pnpShebang`);
const pnpZipBackend = this.opts.project.configuration.get(`pnpZipBackend`);

if (pnpFallbackMode === `dependencies-only`)
for (const pkg of this.opts.project.storedPackages.values())
Expand All @@ -281,6 +282,7 @@ export class PnpInstaller implements Installer {
fallbackExclusionList,
fallbackPool,
ignorePattern,
pnpZipBackend,
packageRegistry,
shebang,
});
Expand Down
17 changes: 17 additions & 0 deletions packages/plugin-pnp/sources/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Hooks as CoreHooks, Plugin, Project, SettingsType, WindowsLinkType} from '@yarnpkg/core';
import {Filename, PortablePath, npath, ppath, xfs} from '@yarnpkg/fslib';
import {Hooks as StageHooks} from '@yarnpkg/plugin-stage';
import {PnpZipBackend} from '@yarnpkg/pnp';
import {pathToFileURL} from 'url';

import {PnpLinker} from './PnpLinker';
Expand Down Expand Up @@ -70,12 +71,14 @@ declare module '@yarnpkg/core' {
nodeLinker: string;
winLinkType: string;
pnpMode: string;
minizip: boolean;
pnpShebang: string;
pnpIgnorePatterns: Array<string>;
pnpEnableEsmLoader: boolean;
pnpEnableInlining: boolean;
pnpFallbackMode: string;
pnpUnpluggedFolder: PortablePath;
pnpZipBackend: PnpZipBackend;
}
}

Expand All @@ -90,6 +93,11 @@ const plugin: Plugin<CoreHooks & StageHooks> = {
type: SettingsType.STRING,
default: `pnp`,
},
minizip: {
description: `Whether Yarn should use minizip to extract archives`,
type: SettingsType.BOOLEAN,
default: false,
},
Comment on lines +96 to +100
Copy link
Member

Choose a reason for hiding this comment

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

Since the main benefit of this PR is to decrease the runtime footprint (by comparison the install doesn't have a lot to gain, since only unplugged packages are extracted on the disk and there's very little of them), I'd rather keep the existing codepath for unplug (to simplify the changes as much as possible).

winLinkType: {
description: `Whether Yarn should use Windows Junctions or symlinks when creating links on Windows.`,
type: SettingsType.STRING,
Expand All @@ -115,6 +123,15 @@ const plugin: Plugin<CoreHooks & StageHooks> = {
default: [],
isArray: true,
},
pnpZipBackend: {
description: `Whether to use the experimental js implementation for the ZipFS`,
type: SettingsType.STRING,
values: [
`libzip`,
`js`,
],
default: `libzip`,
},
pnpEnableEsmLoader: {
description: `If true, Yarn will generate an ESM loader (\`.pnp.loader.mjs\`). If this is not explicitly set Yarn tries to automatically detect whether ESM support is required.`,
type: SettingsType.BOOLEAN,
Expand Down
1 change: 1 addition & 0 deletions packages/yarnpkg-libzip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"devDependencies": {
"@types/prettier": "1.19.0",
"globby": "^11.0.1",
"prettier": "^1.19.1"
},
"dependencies": {
Expand Down
Loading
Loading