Skip to content

perf: cache pnpm lockfile parse to eliminate redundant re-parsing - #999

Merged
sonukapoor merged 2 commits into
mainfrom
feature/issue-837-pnpm-parse-cache
Aug 15, 2026
Merged

perf: cache pnpm lockfile parse to eliminate redundant re-parsing#999
sonukapoor merged 2 commits into
mainfrom
feature/issue-837-pnpm-parse-cache

Conversation

@sonukapoor

Copy link
Copy Markdown
Collaborator

A single scan parsed pnpm-lock.yaml multiple times: the package load, the scanner's workspace map, and the suggested-fix workspace map each read and parsed it independently. YAML parsing dominates lockfile CPU cost (~380ms on a large monorepo), so those redundant parses wasted a real chunk of time on big pnpm projects.

This caches the parsed document per (path, mtime, size) and routes both pnpm loaders through it, so each unchanged lockfile is parsed exactly once. The mtime/size key invalidates automatically after --fix rewrites the lockfile, so a re-scan in the same process still sees fresh contents.

Measured on examples/n8n: 3 pnpm-lock parses down to 1, ~14% faster warm scan, findings byte-identical.

This is the first fix from the performance audit; the network/packument path is a separate follow-up, so this keeps #837 open rather than closing it.

Refs #837

A single scan parsed pnpm-lock.yaml up to four times: the package load,
the scanner's workspace map, the suggested-fix workspace map, and
override context. YAML parsing dominates lockfile CPU cost (~380ms on a
large monorepo), so those redundant parses wasted ~740ms per scan on big
pnpm projects.

Cache the parsed document per (path, mtime, size) and route both pnpm
loaders through it, so each unchanged lockfile is parsed once. The
mtime/size key invalidates automatically after --fix rewrites the file.
Measured on examples/n8n: 3 parses down to 1, ~14% faster warm scan,
findings byte-identical.
Assert an unchanged lockfile is read once across multiple loader calls,
and that a lockfile changed on disk (newer mtime) is re-parsed.
@sonukapoor
sonukapoor merged commit 84e881d into main Aug 15, 2026
6 checks passed
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.

1 participant