Skip to content

Conversation

@redwheelbarrow
Copy link

What's the problem this PR addresses?

Addresses issue #6990 - Reduces the likelihood of large dependencies causing OOM crashes during install

Zip files are all loaded into WASM memory during pnp/pnpm install. The WASM libzip memory is limited to 2gigs. If there are many dependencies, or a few large ones, the limit will be reached and the runtime will crash.

How did you fix it?

Create WASM factory that tracks estimated heap usage in WASM
Construct new WASM for use by a LibzipImpl if heap usage is near max
Cleanup WASM upon discard

Checklist

  • I have read the Contributing Guide.
  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

redwheelbarrow added 2 commits December 8, 2025 18:00
…pkg#6990)

        ## Summary
        Reduce the likelihood of large dependencies causing OOM crashes during install

        ## Problem
        Zip files are all loaded into WASM memory during pnp/pnpm install. The WASM libzip
        memory is limited to 2gigs. If there are many dependencies, or a few large ones,
        the limit will be reached and the runtime will crash.

        ## Solution
        Track the estimated memory usage per LibzipImpl, provide the current WASM or a new WASM
        depending on memory usage estimate. Cleanup WASMs that are no longer needed.

        ## Changes
        - Create WASM factory that tracks estimated heap usage in WASM
        - Construct new WASM for use by a LibzipImpl if heap usage is near max
        - Cleanup WASM upon discard

        ## Testing
        - Unit tests
        - Manually verified the reported issue yarnpkg#6990 is gone
@redwheelbarrow redwheelbarrow changed the title Fix wasm mem 2 fix(#6990): reduce likelihood of libzip OOM in larger repositories Dec 9, 2025
@redwheelbarrow redwheelbarrow changed the title fix(#6990): reduce likelihood of libzip OOM in larger repositories fix(#6990): reduce likelihood of libzip OOM in larger dependency graphs Dec 9, 2025

if (instance.reserved <= 0) {
instance.active = false;
this.instances[reservation.instanceIndex].instance = null;
Copy link
Author

Choose a reason for hiding this comment

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

I'd like to believe the native WASM will get unloaded by being dereferenced, but I don't know.

@redwheelbarrow
Copy link
Author

The problem is the WASM runs out of memory once the size of dependencies gets too large. It's maxed out at 2gigs and there's only a singleton instance. Other solutions:

  1. Chunk the number of files being processed simultaneously during install
  2. Use a different zip implementation (the js impl?)
  3. If the instance is read only, load the zip on demand since it's already in memory (this slows down installs a lot)

}

/**
* Remove the reservation's instance if the previous one has enough space,

Choose a reason for hiding this comment

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

Need to fix doc

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.

2 participants