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

feat(core): add Yarn PnP support #7639

Merged
merged 20 commits into from
Jan 9, 2025
Merged

feat(core): add Yarn PnP support #7639

merged 20 commits into from
Jan 9, 2025

Conversation

hardfist
Copy link
Contributor

@hardfist hardfist commented Aug 21, 2024

Summary

This pull request implements the Yarn PnP feature and closes #2236. Special thanks to @arcanis for implementing PnP resolution in rspack_resolver.

Differences from Webpack Implementation

Intercepting FS on the Rust Side

A significant part of Webpack’s implementation is that it leverages PnP runtime to intercept all filesystem calls in Node.js via the .pnp.cjs file, correctly handling Yarn’s zip file paths as regular files. However, intercepting all filesystem calls on the JavaScript side incurs a significant performance cost in Rspack. Therefore, for performance reasons, Rspack intercepts standard filesystem calls in a custom native FS implementation in rust side.

Enabling PnP Only When resolve.enablePnp is Set

For performance optimization, Yarn PnP is enabled by default only when running in a PnP environment (when process.versions.pnp is truthy). This avoids unnecessary overhead for users not utilizing Yarn PnP.

Limitations

After discussions with @arcanis, supporting multiple Yarn PnP resolver instances would complicate the implementation and negatively impact cache efficiency. Since multiple PnP instances are rarely used in most Yarn PnP applications, Rspack supports only a single PnP resolver instance. Consequently, only the root resolve.enablePnp setting is effective, and settings within module.rule have no impact. This approach suffices for most Yarn PnP applications.

Implementation Caveats

Yarn PnP requires filesystem interception for zip file calls, coupled the filesystem implementation with resolve.enablePnP configuration. Introducing a root enablePnP setting might decouple the filesystem and resolver but could also add confusion and complexity to the configuration. Therefore, I have adhered to the current implementation.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Aug 21, 2024
Copy link

netlify bot commented Aug 21, 2024

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 3dec441
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/677f55ca91be210008d1ae52

@hardfist hardfist changed the title chore: add test case feat(core): add yarn pnp support Aug 21, 2024
@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Aug 21, 2024
@hardfist
Copy link
Contributor Author

!bench

@rspack-bot
Copy link

⏳ Triggered benchmark: Open

@hardfist hardfist requested review from h-a-n-a and SyMind August 21, 2024 07:19
packages/rspack/etc/api.md Outdated Show resolved Hide resolved
crates/node_binding/binding.d.ts Outdated Show resolved Hide resolved
crates/node_binding/src/resolver_factory.rs Outdated Show resolved Hide resolved
crates/node_binding/src/resolver_factory.rs Outdated Show resolved Hide resolved
Copy link

stale bot commented Oct 21, 2024

This pull request has been automatically marked as stale because it has not had recent activity. If this pull request is still relevant, please leave any comment (for example, "bump").

@stale stale bot added the stale label Oct 21, 2024
@arcanis
Copy link
Contributor

arcanis commented Oct 21, 2024

Bump, I still have it in my backlog (I've been in on-and-off paternity leave since August, so my bandwidth has been limited - but I'm still very interested to bring it to the finish line).

@stale stale bot removed the stale label Oct 21, 2024
@hardfist
Copy link
Contributor Author

Bump, I still have it in my backlog (I've been in on-and-off paternity leave since August, so my bandwidth has been limited - but I'm still very interested to bring it to the finish line).

thank you, we'll continue investigating yarn pnp support

Copy link

stale bot commented Dec 21, 2024

This pull request has been automatically marked as stale because it has not had recent activity. If this pull request is still relevant, please leave any comment (for example, "bump").

@stale stale bot added the stale label Dec 21, 2024
@ZeWaka
Copy link

ZeWaka commented Dec 21, 2024

bump

Copy link
Contributor

@arcanis arcanis left a comment

Choose a reason for hiding this comment

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

Looks great to me! Just a couple of nits.

crates/node_binding/src/resolver_factory.rs Outdated Show resolved Hide resolved
crates/rspack_core/src/options/resolve/mod.rs Outdated Show resolved Hide resolved
crates/rspack_fs/src/native_fs.rs Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Jan 2, 2025

📝 Benchmark detail: Open

task failure

Copy link
Contributor

github-actions bot commented Jan 2, 2025

📝 Benchmark detail: Open

Name Base (2025-01-02 9a00d39) Current Change
10000_big_production-mode_disable-minimize + exec 37.3 s ± 234 ms 38.2 s ± 437 ms +2.29 %
10000_development-mode + exec 1.88 s ± 30 ms 1.87 s ± 36 ms -0.63 %
10000_development-mode_hmr + exec 680 ms ± 6.9 ms 673 ms ± 2 ms -0.99 %
10000_production-mode + exec 2.5 s ± 44 ms 2.47 s ± 51 ms -0.93 %
arco-pro_development-mode + exec 1.73 s ± 89 ms 1.76 s ± 71 ms +1.84 %
arco-pro_development-mode_hmr + exec 377 ms ± 2.7 ms 377 ms ± 0.6 ms +0.11 %
arco-pro_production-mode + exec 3.64 s ± 92 ms 3.58 s ± 102 ms -1.56 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.67 s ± 155 ms 3.57 s ± 78 ms -2.61 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.66 s ± 128 ms 3.6 s ± 106 ms -1.66 %
threejs_development-mode_10x + exec 1.52 s ± 22 ms 1.5 s ± 37 ms -0.92 %
threejs_development-mode_10x_hmr + exec 787 ms ± 34 ms 766 ms ± 25 ms -2.59 %
threejs_production-mode_10x + exec 5.37 s ± 95 ms 5.35 s ± 164 ms -0.34 %
10000_big_production-mode_disable-minimize + rss memory 9465 MiB ± 98.4 MiB 9582 MiB ± 33.3 MiB +1.24 %
10000_development-mode + rss memory 659 MiB ± 13.5 MiB 701 MiB ± 38.9 MiB +6.32 %
10000_development-mode_hmr + rss memory 1426 MiB ± 352 MiB 1383 MiB ± 386 MiB -3.04 %
10000_production-mode + rss memory 629 MiB ± 21.3 MiB 669 MiB ± 40 MiB +6.25 %
arco-pro_development-mode + rss memory 576 MiB ± 25.9 MiB 597 MiB ± 47.2 MiB +3.68 %
arco-pro_development-mode_hmr + rss memory 624 MiB ± 42 MiB 640 MiB ± 92 MiB +2.45 %
arco-pro_production-mode + rss memory 743 MiB ± 64.5 MiB 738 MiB ± 40 MiB -0.63 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 743 MiB ± 39.9 MiB 737 MiB ± 50.5 MiB -0.71 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 751 MiB ± 51.1 MiB 737 MiB ± 66.5 MiB -1.86 %
threejs_development-mode_10x + rss memory 613 MiB ± 23.4 MiB 613 MiB ± 18.9 MiB -0.02 %
threejs_development-mode_10x_hmr + rss memory 1175 MiB ± 68.7 MiB 1126 MiB ± 126 MiB -4.16 %
threejs_production-mode_10x + rss memory 857 MiB ± 44.9 MiB 896 MiB ± 57.9 MiB +4.60 %

Copy link
Contributor

github-actions bot commented Jan 3, 2025

📝 Benchmark detail: Open

Name Base (2025-01-03 649c656) Current Change
10000_big_production-mode_disable-minimize + exec 37.6 s ± 265 ms 38 s ± 549 ms +1.23 %
10000_development-mode + exec 1.89 s ± 24 ms 1.86 s ± 26 ms -1.80 %
10000_development-mode_hmr + exec 677 ms ± 14 ms 671 ms ± 6.3 ms -0.80 %
10000_production-mode + exec 2.52 s ± 76 ms 2.46 s ± 45 ms -2.14 %
arco-pro_development-mode + exec 1.74 s ± 81 ms 1.79 s ± 71 ms +2.99 %
arco-pro_development-mode_hmr + exec 377 ms ± 1.5 ms 376 ms ± 1.8 ms -0.14 %
arco-pro_production-mode + exec 3.64 s ± 80 ms 3.59 s ± 117 ms -1.28 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.66 s ± 97 ms 3.6 s ± 87 ms -1.74 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.65 s ± 70 ms 3.6 s ± 92 ms -1.39 %
threejs_development-mode_10x + exec 1.5 s ± 22 ms 1.48 s ± 17 ms -1.16 %
threejs_development-mode_10x_hmr + exec 780 ms ± 18 ms 771 ms ± 30 ms -1.23 %
threejs_production-mode_10x + exec 5.38 s ± 127 ms 5.33 s ± 147 ms -0.99 %
10000_big_production-mode_disable-minimize + rss memory 9517 MiB ± 179 MiB 9589 MiB ± 47.8 MiB +0.76 %
10000_development-mode + rss memory 650 MiB ± 10.7 MiB 714 MiB ± 23.8 MiB +9.83 %
10000_development-mode_hmr + rss memory 1371 MiB ± 227 MiB 1512 MiB ± 293 MiB +10.27 %
10000_production-mode + rss memory 625 MiB ± 18.8 MiB 710 MiB ± 49.3 MiB +13.57 %
arco-pro_development-mode + rss memory 589 MiB ± 30.1 MiB 599 MiB ± 42.2 MiB +1.73 %
arco-pro_development-mode_hmr + rss memory 635 MiB ± 85.2 MiB 648 MiB ± 64.9 MiB +2.09 %
arco-pro_production-mode + rss memory 749 MiB ± 48.7 MiB 752 MiB ± 54.4 MiB +0.37 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 725 MiB ± 45.5 MiB 771 MiB ± 49.6 MiB +6.43 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 734 MiB ± 41.6 MiB 768 MiB ± 41 MiB +4.58 %
threejs_development-mode_10x + rss memory 589 MiB ± 20.5 MiB 648 MiB ± 28.7 MiB +9.90 %
threejs_development-mode_10x_hmr + rss memory 1135 MiB ± 200 MiB 1133 MiB ± 249 MiB -0.15 %
threejs_production-mode_10x + rss memory 852 MiB ± 24.9 MiB 984 MiB ± 78.8 MiB +15.43 %

@hardfist hardfist requested a review from chenjiahan January 6, 2025 02:36
@hardfist hardfist requested a review from ahabhgk January 9, 2025 03:11
@hardfist hardfist enabled auto-merge (squash) January 9, 2025 05:31
@hardfist hardfist merged commit 5b73853 into main Jan 9, 2025
30 checks passed
@hardfist hardfist deleted the yj/pnp-support branch January 9, 2025 05:31
@chenjiahan chenjiahan changed the title feat(core): add yarn pnp support feat(core): add Yarn PnP support Jan 9, 2025
@NyanHelsing
Copy link

nice work!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Yarn PnP workspace
7 participants