Skip to content

feat(lockfile): add split lockfile storage mode - #11247

Closed
nhomble wants to merge 1 commit into
pnpm:mainfrom
nhomble:feat/split-lockfile-storage
Closed

nhomble wants to merge 1 commit into
pnpm:mainfrom
nhomble:feat/split-lockfile-storage

Conversation

@nhomble

@nhomble nhomble commented Apr 13, 2026 •

Copy link
Copy Markdown

Add lockfileStorage: split setting that stores per-package lockfiles while using the fast shared resolution path. Before resolution, per-package lockfiles are merged into a temporary unified lockfile. After resolution via mutateModules(), the result is split back into per-package files using filterLockfileByImporters + pruneSharedLockfile.

This avoids the ~10x performance penalty of shared-workspace-lockfile=false (which runs N independent install cycles) while still providing per-package lockfiles that reduce git merge conflicts and improve CI cache granularity in large monorepos.

Includes a .pnpm-split-in-progress sentinel file for crash recovery.

AI Usage:

Out of transparency, I did use opus 4.6 to help me do the analysis and prepare the code change, but the pain points I mentioned in #8334 are real and I'd be happy to report back the results.

Refs:

@nhomble
nhomble requested a review from zkochan as a code owner April 13, 2026 03:40
@nhomble
nhomble force-pushed the feat/split-lockfile-storage branch from 87f9e5a to 72f97a1 Compare April 13, 2026 03:51
@nhomble

nhomble commented Apr 13, 2026 •

Copy link
Copy Markdown
Author

To benchmark, I just created a 200 package repo with some nestjs dependencies that would enable building a simple hello world http server and then I did a pnpm install with a shared lockfile, lockfile per package (what currently happens when you set the root lockfile to false), and then I tried my split mode. I saw the split mode had performance on par with the shared lockfile (which is what we wanted!)

@patricktree

Copy link
Copy Markdown
Contributor

I had the same idea about 2 years ago (main...patricktree:pnpm:feat/lockfile-per-workspace-project), and still think this would be great.
Tools like turborepo would probably need to adapt to the split lockfiles, but IMO it is worth it:

  • comparing hashes of two versions of a split lockfile would be enough to determine "did a dependency of this workspace project change"
  • would make it easier for engineers to see where a dependency changed (currently, many PRs have a change affecting the monorepo pnpm-lockfile.yaml and it is difficult to see what really changed)

@nhomble
nhomble force-pushed the feat/split-lockfile-storage branch 3 times, most recently from 9cbefcf to f19c361 Compare April 14, 2026 18:23
@nhomble

nhomble commented Apr 14, 2026

Copy link
Copy Markdown
Author

Sorry for the noise earlier, the CI passes on my fork. I https://github.com/nhomble/pnpm/actions/runs/24415887094 there was a separate change needed for a different dependency that I figured would deserve its own changeset so I didn't cherry pick into this pr: f1cf4db#diff-18ae0a0fab29a7db7aded913fd05f30a2c8f6c104fadae86c9d217091709794cR410

@nhomble

nhomble commented Apr 18, 2026 •

Copy link
Copy Markdown
Author

Is it preferred to wait until there's agreement on the changeset or should I preemptively resolve the conflict and wait for CI to be reran @zkochan? I'm happy to do whatever helps out.

Add `lockfileStorage: split` setting that stores per-package lockfiles
while using the fast shared resolution path.

```
sharedWorkspaceLockfile: false
lockfileStorage: split
```
@nhomble
nhomble force-pushed the feat/split-lockfile-storage branch from f19c361 to c9bc09d Compare April 25, 2026 20:38
@nhomble

nhomble commented Apr 28, 2026

Copy link
Copy Markdown
Author

@zkochan I apologize for jumping straight into a solution. Maybe we can use this MR thread or the linked issues to discuss/groom other strategies for 100+ package monorepos dealing with conflicting lockfiles.

I can definitely sympathize any apprehension to adding a whole new lockfile style. If there is an alternative, I'm more than happy to try it.

@zkochan

zkochan commented Apr 30, 2026

Copy link
Copy Markdown
Member

I think you can already make the existing install with dedicated lockfiles fast by enabling the global virtual store: https://pnpm.io/11.x/settings#enableglobalvirtualstore

I personally don't understand why it is useful to have dedicated lockfiles.

@nhomble

nhomble commented Apr 30, 2026 •

Copy link
Copy Markdown
Author

I think you can already make the existing install with dedicated lockfiles fast by enabling the global virtual store: https://pnpm.io/11.x/settings#enableglobalvirtualstore

I personally don't understand why it is useful to have dedicated lockfiles.

I apologize for misunderstanding. For the global virtual stores,

Using a global virtual store can significantly speed up installations when a warm cache is available. However, in CI environments (where caches are typically absent), it may slow down installation. If pnpm detects that it is running in CI, this setting is automatically disabled.

I don't know how this will help me with slow installs in my CI environment (if I turn off shared lockfile).

At least in practice,

why it is useful to have dedicated lockfiles.

has only been proposed in my team as a way to reduce the number of conflicts in the central lockfile. When new projects are added or dependencies are just added a subset of projects, we are hoping for less conflicts to happen in the distributed lockfiles.

@zkochan

zkochan commented Apr 30, 2026

Copy link
Copy Markdown
Member

Don't you think the amount of conflicts will actually grow as now the same conflicts will happen in multiple files instead of just one file?

@nhomble

nhomble commented Apr 30, 2026

Copy link
Copy Markdown
Author

Don't you think the amount of conflicts will actually grow as now the same conflicts will happen in multiple files instead of just one file?

Conflicts with the pnpm-lock files seem pretty binary to me because in a conflict, I've seen it recommended (I'll try to find and link) that the clearest resolution path is just to let pnpm rebuild the lockfile.

What does change with the many files is that local changes to a pnpm package have a smaller chance of conflicting with another team's package change. Some examples:

  • adding a new dependency for just their package
  • creating a new package in the repo

These examples shouldn't cause conflicts since they're isolated to a specific lockfile.


Where I can agree is when we do changes in the pnpm-workspace.yaml for the catalog:. In that case, we would affect many files. But in this case, I come back to the binary nature of the problem. If I get a conflict, I will just rerun pnpm install.

If there are better strategies for this process, I would be happy to adapt.


Finally, maybe you could teach me more about the original intent of the configuration to disable a root lockfile. I thought this was the problem you were trying to solve, but if I am misunderstanding the use of this feature I could try something else.

FWIW we did consider the branch per lockfile mode, the multi step process to prune and merge the branch lockfiles on trunk was not appealing.

@zkochan

zkochan commented Apr 30, 2026

Copy link
Copy Markdown
Member

Finally, maybe you could teach me more about the original intent of the configuration to disable a root lockfile. I thought this was the problem you were trying to solve, but if I am misunderstanding the use of this feature I could try something else.

It was just the very first implementation of multi-package support. I believe it was easier to implement it this way (in 2016). But then people started using it and now it is hard to remove. I personally don't see a point in multiple lockfiles.

adding a new dependency for just their package
creating a new package in the repo

so this is only conflicts in the "importers" section. If you update a transitive dependency in one project the same update will happen in multiple other lockfiles increasing the area for conflicts. So maybe you will reduce one type of conflicts but won't eliminate conflicts.

@nhomble

nhomble commented Apr 30, 2026

Copy link
Copy Markdown
Author

The context on the initial implementation is helpful. Beyond just the conflicts, it's probably unwise then for any project to stick to a feature you would prefer gets deprecated.

So maybe you will reduce one type of conflicts but won't eliminate conflicts.

For sure... if it's ok, maybe we take a step back from this implementation and consider this more of a discussion (I'd be happy to migrate to another github issue if that's preferred for SEO).

Are there any other preferred strategies for this conflict problem?

@zkochan

zkochan commented Apr 30, 2026

Copy link
Copy Markdown
Member

I am not sure because the current lockfile format is the result of several iterations already that were aimed at reducing the number of conflicts. And pnpm install automatically resolves conflicts. In general changing the lockfile is not impossible but a hard task. Especially now that there are so many pnpm users. But this issue is related: #11378

@nhomble

nhomble commented Apr 30, 2026

Copy link
Copy Markdown
Author

And pnpm install automatically resolves conflicts

Yep, I noticed that pnpm resolver project as well. The issue in my case is that we are using gitlab saas so it doesn't matter what I configure locally if gitlab treats the mr as conflicted.

Before I migrate to the linked issue, are you thinking there's no point to improve the performance of the distributed lockfile then going forward for pnpm (such that I should close this pr)?

@zkochan

zkochan commented Apr 30, 2026

Copy link
Copy Markdown
Member

The problem that you try to solve with conflicts in the importers section would be solved best by moving direct resolutions of dependencies into separate lockfiles. Like this

pnpm/pnpm-lock.yaml

Lines 3078 to 3085 in 4bf61ba

deps/compliance/license-resolver:
devDependencies:
'@jest/globals':
specifier: 'catalog:'
version: 30.3.0
'@pnpm/deps.compliance.license-resolver':
specifier: workspace:*
version: 'link:'
would be in a file like deps/compliance/license-resolver/pnpm-lock-importer.yaml. But then we add a lot of additional file system operations to read all those additional files. I am not sure it makes sense. Maybe with AI we can come up with a solution that eliminates diffs, I don't know.

@nhomble

nhomble commented Apr 30, 2026 •

Copy link
Copy Markdown
Author

thanks for the ref! I'll check it out.

add a lot of additional file system operations

this specifically seemed to be the insight in this changeset with the distributed lockfile. Actually reading all of the files once and merging into a single in-memory representation was a lot more efficient than doing the operations on a per file basis

@zkochan

zkochan commented Nov 20, 2026

Copy link
Copy Markdown
Member

i am closing it for now. We can discuss it in a discussion if needed

@zkochan zkochan closed this Nov 20, 2026
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.

3 participants