perf: cache pnpm lockfile parse to eliminate redundant re-parsing - #999
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A single scan parsed
pnpm-lock.yamlmultiple 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
--fixrewrites 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