Skip to content

perf(lockfile): stream the env document out of the lockfile - #13820

Merged
zkochan merged 4 commits into
mainfrom
perf-13819
Aug 11, 2026
Merged

zkochan merged 4 commits into
mainfrom
perf-13819

Conversation

@zkochan

@zkochan zkochan commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Summary

EnvLockfile::read loaded the whole pnpm-lock.yaml into a String and sliced the leading env document out of it. Since the switch to the project's package-manager version, that read happens on every command in a project that pins pnpm (devEngines.packageManager, or a packageManager field with a v12+ major) — most projects — to consume a document that is a fraction of a percent of the file. In this repository the env document is 2,915 bytes of an 821,592-byte lockfile.

This ports streamReadFirstYamlDocument from pnpm11/lockfile/fs/src/yamlDocuments.ts, which the TypeScript CLI already uses: read in 64 KB chunks, reject a file that does not begin with ---\n as soon as those 4 bytes are in, and return as soon as the \n---\n that closes the env document is found. The cost is now flat in the size of the lockfile — reading the env document out of an 8 MB lockfile takes ~15µs instead of ~390µs, and the whole-file UTF-8 validation and the second full copy that normalize_lockfile_content allocated on a CRLF checkout are both gone.

BOM stripping and CRLF normalization happen per chunk instead of over the whole file, withholding a carriage return that ends a chunk until the next chunk says whether an LF follows it.

The other EnvLockfile::read callers — self_update, with, audit, and the env-installer — get the win for free.

This is a pure perf gap in the Rust stack. Behavior, output, and file format are identical in both stacks, so there is nothing to mirror on the TypeScript side.

Closes #13819

Squash Commit Body

`EnvLockfile::read` loaded the whole `pnpm-lock.yaml` into a `String` and
sliced the leading env document out of it. Since the switch to the
project's package-manager version, that read happens on every command in
a project that pins pnpm through `devEngines.packageManager` or a v12+
`packageManager` field — most projects — to consume a document that is a
fraction of a percent of the file.

Read the file in 64 KB chunks instead, stopping at the separator that
closes the env document, and rejecting a lockfile that does not begin
with `---\n` as soon as those 4 bytes are in. The cost is now flat in the
size of the lockfile: on an 8 MB lockfile, reading the env document takes
~15µs instead of ~390µs.

The BOM and CRLF normalization that `normalize_lockfile_content` did over
the whole file happens per chunk, withholding a carriage return that ends
a chunk until the next one says whether an LF follows it.

This mirrors `streamReadFirstYamlDocument` in
`pnpm11/lockfile/fs/src/yamlDocuments.ts`, which the TypeScript CLI
already uses. Behavior, output, and file format are unchanged in both
stacks, so there is nothing to port back.

Closes pnpm/pnpm#13819

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting. (The
    TypeScript CLI already streams the env document; this brings the Rust port
    in line. Nothing to port back.)
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

Written by an agent (Claude Code, claude-opus-5).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Performance

    • Improved lockfile environment-document reading by processing only the required initial section.
    • Reduced memory usage and improved performance for large lockfiles, especially during downloads.
  • Reliability

    • Improved handling of UTF-8 BOMs, CRLF line endings, chunk boundaries, missing documents, interrupted reads, and invalid UTF-8.
    • Added coverage for large, malformed, and varied lockfile formats.

`EnvLockfile::read` loaded the whole `pnpm-lock.yaml` into a `String` and
sliced the leading env document out of it. Since the switch to the
project's package-manager version, that read happens on every command in
a project that pins pnpm through `devEngines.packageManager` or a v12+
`packageManager` field — most projects — to consume a document that is a
fraction of a percent of the file.

Read the file in 64 KB chunks instead, stopping at the separator that
closes the env document, and rejecting a lockfile that does not begin
with `---\n` as soon as those 4 bytes are in. The cost is now flat in the
size of the lockfile: on an 8 MB lockfile, reading the env document takes
~15µs instead of ~390µs.

The BOM and CRLF normalization that `normalize_lockfile_content` did over
the whole file happens per chunk, withholding a carriage return that ends
a chunk until the next one says whether an LF follows it.

This mirrors `streamReadFirstYamlDocument` in
`pnpm11/lockfile/fs/src/yamlDocuments.ts`, which the TypeScript CLI
already uses. Behavior, output, and file format are unchanged in both
stacks, so there is nothing to port back.

Closes #13819
Copilot AI lite review requested due to automatic review settings August 11, 2026 08:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 323789e4-19a4-4d9c-a404-ef0a8e13c71a

📥 Commits

Reviewing files that changed from the base of the PR and between 174f88f and 25bf6ec.

📒 Files selected for processing (1)
  • pnpm/crates/lockfile/src/yaml_documents/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm/crates/lockfile/src/yaml_documents/tests.rs

📝 Walkthrough

Walkthrough

The lockfile crate now reads only the leading YAML document in bounded chunks. It handles BOM, CRLF, chunk boundaries, missing documents, interrupted reads, and invalid UTF-8. EnvLockfile::read uses this reader, with tests and documentation updated.

Changes

Environment lockfile streaming

Layer / File(s) Summary
Streaming YAML document reader
pnpm/crates/lockfile/src/yaml_documents.rs
Added bounded first-document reads with incremental BOM handling, CRLF normalization, separator detection, and I/O error reporting.
Environment lockfile integration
pnpm/crates/lockfile/src/env_lockfile.rs, pnpm/crates/cli/src/cli_args/pre_command.rs, .changeset/stream-env-lockfile-document.md
EnvLockfile::read now uses the streaming reader. Documentation and release metadata describe the updated behavior.
Streaming reader validation
pnpm/crates/lockfile/src/yaml_documents/tests.rs
Added coverage for chunk boundaries, document variants, read limits, large documents, missing documents, interrupted reads, and invalid UTF-8.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant EnvLockfile
  participant read_env_document
  participant read_first_yaml_document
  participant LockfileReader
  EnvLockfile->>read_env_document: open lockfile with symlink following
  read_env_document->>read_first_yaml_document: read first YAML document
  read_first_yaml_document->>LockfileReader: read bounded chunks
  LockfileReader-->>read_first_yaml_document: return chunked bytes
  read_first_yaml_document-->>read_env_document: return document or I/O error
  read_env_document-->>EnvLockfile: return environment document or None
Loading

Assessment against linked issues

Objective Addressed Explanation
[Issue #13819] Read only the leading YAML document in bounded chunks and stop at the document separator. ✅
[Issue #13819] Preserve BOM, CRLF, chunk-boundary, large-document, and missing-document behavior. ✅
[Issue #13819] Use the streaming reader from EnvLockfile::read. ✅

Possibly related PRs

  • pnpm/pnpm#13075: Both changes update environment-document reads and symlink-following behavior.
  • pnpm/pnpm#13609: Both changes update YAML document handling, including CRLF and BOM processing.

Suggested labels: product: pacquet

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf-13819

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Perf: stream env YAML document from pnpm-lock.yaml

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Stream-read only the leading env YAML document instead of loading full pnpm-lock.yaml.
• Normalize BOM/CRLF incrementally while scanning for the document separator.
• Add exhaustive chunk-boundary tests and a changeset documenting the perf win.
Diagram

graph TD
  CLI["pnpm CLI command"] --> EnvRead["EnvLockfile::read"] --> Stream["read_env_document"] --> Lock[("pnpm-lock.yaml")] --> YamlRead["read_first_yaml_document"] --> EnvDoc["Env YAML string"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. BufRead + read_until("\n---\n")
  • ➕ Simpler implementation using buffered reads and delimiter search
  • ➕ Potentially fewer manual edge cases around chunking
  • ➖ Still needs explicit handling for BOM + CRLF normalization and delimiter spanning boundaries
  • ➖ May read more data than necessary depending on buffering behavior
2. Memory-map the lockfile (mmap) and slice
  • ➕ Very fast random access and delimiter search without explicit chunk loops
  • ➕ Keeps code relatively straightforward once mapped
  • ➖ More platform-specific behavior and failure modes (Windows semantics, large files)
  • ➖ Still pays the cost of mapping/validating more of the file than needed for small env docs

Recommendation: The chosen chunked streaming approach is a good fit: it minimizes I/O for the common case (small env doc, huge lockfile), matches existing pnpm TypeScript behavior, and explicitly preserves BOM/CRLF normalization semantics. Keep this approach; alternatives add complexity or risk without clear wins.

Files changed (5) +273 / -28

Enhancement (2) +135 / -24
env_lockfile.rsSwitch EnvLockfile::read to streaming env-document extraction +15/-19

Switch EnvLockfile::read to streaming env-document extraction

• Replaces whole-file lockfile reads with a targeted 'read_env_document' path that streams only the first YAML document. Preserves existing behavior (returns None when no env doc exists) while preventing the main lockfile document from being loaded into memory.

pnpm/crates/lockfile/src/env_lockfile.rs

yaml_documents.rsAdd read_first_yaml_document streaming reader with per-chunk normalization +120/-5

Add read_first_yaml_document streaming reader with per-chunk normalization

• Introduces a chunked reader that extracts the first YAML document by scanning for the document start and separator, stopping as soon as the env doc closes. Implements incremental BOM stripping and CRLF normalization across chunk boundaries and validates UTF-8 only for the extracted env document.

pnpm/crates/lockfile/src/yaml_documents.rs

Tests (1) +130 / -1
tests.rsAdd comprehensive tests for streamed YAML document reading +130/-1

Add comprehensive tests for streamed YAML document reading

• Adds boundary-focused tests across many chunk sizes (including 1 byte) to cover BOM, CRLF normalization, missing separators, long env docs, early-stop behavior, and invalid UTF-8 handling. Ensures streaming results match the existing non-stream extraction logic.

pnpm/crates/lockfile/src/yaml_documents/tests.rs

Documentation (2) +8 / -3
stream-env-lockfile-document.mdAdd changeset noting streamed env-doc lockfile read +5/-0

Add changeset noting streamed env-doc lockfile read

• Documents the performance improvement from streaming only the leading env YAML document instead of reading the full pnpm-lock.yaml, including a concrete micro-benchmark comparison.

.changeset/stream-env-lockfile-document.md

pre_command.rsClarify comment about avoiding duplicate env-lockfile parsing +3/-3

Clarify comment about avoiding duplicate env-lockfile parsing

• Updates the inline documentation to reflect that the cost is in re-reading and re-parsing the env lockfile (rather than necessarily reading the whole file). No functional behavior changes.

pnpm/crates/cli/src/cli_args/pre_command.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/stream-env-lockfile-document.md:
- Line 5: Update the bounded-read description to state that the reader consumes
only the initial chunks needed to locate the leading environment document or
determine that it is absent, rather than claiming it reads only the first chunk.
Preserve the performance comparison and user-visible behavior description.

In `@pnpm/crates/lockfile/src/yaml_documents.rs`:
- Around line 86-100: The read_first_yaml_document_in_chunks function must probe
only the minimum bytes needed to validate the YAML document marker, including
BOM and CRLF disambiguation, before switching to READ_BUFFER_SIZE streaming
reads; reject marker-less input after the initial four-byte boundary. Update
pnpm/crates/lockfile/src/yaml_documents.rs lines 86-100 accordingly, and change
pnpm/crates/lockfile/src/yaml_documents/tests.rs lines 132-139 to assert the
bounded initial read limit rather than READ_BUFFER_SIZE.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2ee25e68-aab7-48c1-94c7-46b0a2f16806

📥 Commits

Reviewing files that changed from the base of the PR and between 1c42ae2 and cacd1f8.

📒 Files selected for processing (5)
  • .changeset/stream-env-lockfile-document.md
  • pnpm/crates/cli/src/cli_args/pre_command.rs
  • pnpm/crates/lockfile/src/env_lockfile.rs
  • pnpm/crates/lockfile/src/yaml_documents.rs
  • pnpm/crates/lockfile/src/yaml_documents/tests.rs

@greptile-apps

greptile-apps Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously reported interrupted-read path now retries while preserving reader and parser state, with regression coverage.

Reviews (4): Last reviewed commit: "test(lockfile): log the streamed documen..." | Re-trigger Greptile

`read_to_string`, which the streaming env-document read replaced, retries
a read interrupted by a signal. The chunked loop propagated `EINTR`
instead, so a signal arriving mid-read would fail the command.

Also state in the changeset that reading stops at the end of the env
document, rather than after the first chunk — an env document larger than
64 KB takes more than one.
Copilot AI review requested due to automatic review settings August 11, 2026 08:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

greptile-apps[bot]
greptile-apps Bot previously approved these changes Aug 11, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
pnpm/crates/lockfile/src/yaml_documents.rs (1)

102-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rewrite the retry comment to describe current behavior.

The comment refers to the implementation that this code replaced. It also repeats Read::read_to_string behavior. Keep only the reason for the local retry.

Proposed comment
-            // `Read::read_to_string`, which this replaces on the lockfile
-            // read path, retries a signal-interrupted read rather than
-            // failing the command.
+            // Retry `io::ErrorKind::Interrupted` so a transient signal does
+            // not abort lockfile loading.

As per path instructions, comments must document contracts, non-obvious invariants, workarounds, deliberate exceptions, or unavoidable technical constraints, and must describe current behavior rather than historical implementation details.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm/crates/lockfile/src/yaml_documents.rs` around lines 102 - 104, Update
the retry comment in the lockfile read path to remove the historical
`Read::read_to_string` reference and avoid restating its behavior. Keep only the
current reason for the local retry, documenting the relevant non-obvious
contract or technical constraint.

Source: Path instructions

pnpm/crates/lockfile/src/yaml_documents/tests.rs (1)

46-60: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Log YAML values before assertions

assert_streams compares multiline and large YAML documents without diagnostic logging. Log the actual and expected values before the relevant assert_eq! calls.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm/crates/lockfile/src/yaml_documents/tests.rs` around lines 46 - 60,
Update the test helper assert_streams to log the actual and expected YAML values
immediately before each relevant assert_eq! call, including both chunked and
non-chunked reads, so multiline or large-document mismatches are diagnosable.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pnpm/crates/lockfile/src/yaml_documents.rs`:
- Around line 102-104: Update the retry comment in the lockfile read path to
remove the historical `Read::read_to_string` reference and avoid restating its
behavior. Keep only the current reason for the local retry, documenting the
relevant non-obvious contract or technical constraint.

In `@pnpm/crates/lockfile/src/yaml_documents/tests.rs`:
- Around line 46-60: Update the test helper assert_streams to log the actual and
expected YAML values immediately before each relevant assert_eq! call, including
both chunked and non-chunked reads, so multiline or large-document mismatches
are diagnosable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 29ddcce7-9e4e-4411-8632-37933b6cb5ac

📥 Commits

Reviewing files that changed from the base of the PR and between cacd1f8 and d07cfc8.

📒 Files selected for processing (3)
  • .changeset/stream-env-lockfile-document.md
  • pnpm/crates/lockfile/src/yaml_documents.rs
  • pnpm/crates/lockfile/src/yaml_documents/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/stream-env-lockfile-document.md

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Aug 11, 2026
@codecov-commenter

codecov-commenter commented Aug 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.70115% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.27%. Comparing base (1c42ae2) to head (25bf6ec).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pnpm/crates/lockfile/src/env_lockfile.rs 87.50% 1 Missing ⚠️
pnpm/crates/lockfile/src/yaml_documents.rs 98.73% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #13820    +/-   ##
========================================
  Coverage   88.26%   88.27%            
========================================
  Files         624      624            
  Lines      101978   102132   +154     
========================================
+ Hits        90014    90156   +142     
- Misses      11964    11976    +12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     12.8±0.57ms    29.3 MB/sec    1.18     15.1±0.87ms    24.8 MB/sec
packument/parse                                  1.00     41.3±0.39µs  1607.9 MB/sec    1.00     41.3±2.23µs  1607.7 MB/sec
tarball/download_dependency                      1.32      3.4±0.62ms  1286.0 KB/sec    1.00      2.6±0.18ms  1696.1 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.06   217.0±12.77ms 73.7 KElem/sec    1.00    204.4±9.50ms 78.3 KElem/sec
workspace_resolution/hoist_heavy                 1.00   292.0±20.86ms        ? ?/sec    1.30   379.1±23.40ms        ? ?/sec

The retry comment described the read this code replaced instead of the
reason for the retry. The streaming test helper compares multiline
documents, which the style guide asks to log with `eprintln!` before the
assertion so a failure is readable.
@qodo-code-review

qodo-code-review Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset file declares a bump only for pacquet and does not include a required pnpm
entry. This can cause the pnpm package release metadata to be incomplete or incorrect.
Code

.changeset/stream-env-lockfile-document.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

●● Moderate

Mixed history: some PRs add required pnpm entry; others explicitly reject doing so.

PR-#13748
PR-#13787

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changesets to explicitly include a pnpm package entry with a
valid bump type. The added changeset front-matter only includes pacquet: patch and omits pnpm.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/stream-env-lockfile-document.md[1-3]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new changeset does not declare a bump for the `pnpm` package, which is required.

## Issue Context
This PR adds `.changeset/stream-env-lockfile-document.md` with only a `pacquet` entry.

## Fix Focus Areas
- .changeset/stream-env-lockfile-document.md[1-3]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Invalid UTF-8 ignored 🐞 Bug ☼ Reliability
Description
read_first_yaml_document_in_chunks returns Ok(None) at EOF without UTF-8 validating the bytes it
already buffered when the closing \n---\n separator is missing. This can make a corrupted
pnpm-lock.yaml look like it has no env document, changing downstream behavior in
EnvLockfile::read callers that previously failed on invalid UTF-8 during whole-file reads.
Code

pnpm/crates/lockfile/src/yaml_documents.rs[R108-111]

+        if read == 0 {
+            // A withheld carriage return is then the file's last byte,
+            // and no separator ends in one, so it cannot complete one.
+            return Ok(None);
Relevance

●● Moderate

Tightens lockfile parsing/UTF-8 failure behavior; no close precedent, and team sometimes avoids
extra rejection paths.

PR-#13748
PR-#13075

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The EOF path returns Ok(None) before any UTF-8 conversion, while UTF-8 validation occurs only when
a separator is found. EnvLockfile::read treats None as “no env document”, so a
malformed/unterminated env doc with invalid bytes can be silently treated as absent instead of
failing the read.

pnpm/crates/lockfile/src/yaml_documents.rs[90-141]
pnpm/crates/lockfile/src/env_lockfile.rs[115-124]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`read_first_yaml_document_in_chunks()` returns `Ok(None)` on EOF even if it has accumulated non-empty bytes (including bytes after a valid `---\n` prefix) and those bytes are not valid UTF-8. Because UTF-8 validation only happens on the “separator found” path (`String::from_utf8(content)`), a malformed/unterminated env document can mask lockfile corruption.

### Issue Context
Lockfiles are treated as attacker-controlled input in this repo. The pre-command path uses `EnvLockfile::read()` to decide whether to sync/repair the env lockfile; changing “corrupt lockfile” into “no env document” can lead to confusing behavior and different error reporting.

### Fix Focus Areas
- pnpm/crates/lockfile/src/yaml_documents.rs[108-134]

### Suggested fix approach
- When `read == 0` (EOF):
 - If `withheld_carriage_return` is true, flush it into `content` (push `b'\r'`) so normalization doesn’t drop the last byte.
 - If `content` is non-empty, validate it as UTF-8 (e.g., `std::str::from_utf8(&content)`), and if invalid return `io::ErrorKind::InvalidData`.
 - Then return `Ok(None)`.
- Add a regression unit test covering invalid UTF-8 before EOF **without** a separator (e.g., `---\nfoo: <invalid bytes>` with EOF) expecting `InvalidData`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

3. Verbose test logging ✓ Resolved 🐞 Bug ➹ Performance ⭐ New
Description
assert_streams() unconditionally eprintln!s the full expected/read/extracted env document
multiple times; when invoked with the large env document test (repeat(10_000)), this needlessly
generates and captures a large amount of output even on success, slowing tests and increasing
memory/log volume (especially with --nocapture).
Code

pnpm/crates/lockfile/src/yaml_documents/tests.rs[52]

+    eprintln!("EXPECTED ENV DOCUMENT:\n{}\n", expected.unwrap_or("<none>"));
Relevance

● Weak

Team previously rejected removing unconditional dbg!/eprintln! from tests to keep diagnostics in
logs.

PR-#13748

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The focus-area change adds multiple unconditional eprintln! calls in assert_streams(). That
helper is used by a test that constructs an env document with 10,000 repeated lines, so the logged
payload becomes very large and is printed repeatedly for multiple chunk sizes.

pnpm/crates/lockfile/src/yaml_documents/tests.rs[47-65]
pnpm/crates/lockfile/src/yaml_documents/tests.rs[118-123]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`assert_streams()` prints entire documents to stderr unconditionally. For the large env-document test case, this creates substantial output and overhead even when assertions pass.

### Issue Context
Rust's test harness typically captures stdout/stderr; generating large strings and writing them repeatedly adds runtime and memory pressure, and `--nocapture` (or CI configurations that show captured output) can produce noisy logs.

### Fix Focus Areas
- pnpm/crates/lockfile/src/yaml_documents/tests.rs[52-64]

### Suggested fix
- Remove the `eprintln!` calls entirely, or gate them behind an env var (e.g., `if std::env::var_os("PNPM_TEST_DEBUG").is_some() { ... }`).
- If diagnostics are desired, print only lengths / small prefixes (bounded output) rather than full documents.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context used
✅ Compliance rules (platform): 26 rules

Grey Divider

Tip of the day
💡 Did you know, you can group findings by type and pick your Finding display, from Minimal to Full

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous review results

Review updated until commit 25bf6ec

Results up to commit d07cfc8 ⚖️ Balanced


🐞 Bugs (1) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset file declares a bump only for pacquet and does not include a required pnpm
entry. This can cause the pnpm package release metadata to be incomplete or incorrect.
Code

.changeset/stream-env-lockfile-document.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

●● Moderate

Mixed history: some PRs add required pnpm entry; others explicitly reject doing so.

PR-#13748
PR-#13787

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changesets to explicitly include a pnpm package entry with a
valid bump type. The added changeset front-matter only includes pacquet: patch and omits pnpm.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/stream-env-lockfile-document.md[1-3]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new changeset does not declare a bump for the `pnpm` package, which is required.

## Issue Context
This PR adds `.changeset/stream-env-lockfile-document.md` with only a `pacquet` entry.

## Fix Focus Areas
- .changeset/stream-env-lockfile-document.md[1-3]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Invalid UTF-8 ignored 🐞 Bug ☼ Reliability
Description
read_first_yaml_document_in_chunks returns Ok(None) at EOF without UTF-8 validating the bytes it
already buffered when the closing \n---\n separator is missing. This can make a corrupted
pnpm-lock.yaml look like it has no env document, changing downstream behavior in
EnvLockfile::read callers that previously failed on invalid UTF-8 during whole-file reads.
Code

pnpm/crates/lockfile/src/yaml_documents.rs[R108-111]

+        if read == 0 {
+            // A withheld carriage return is then the file's last byte,
+            // and no separator ends in one, so it cannot complete one.
+            return Ok(None);
Relevance

●● Moderate

Tightens lockfile parsing/UTF-8 failure behavior; no close precedent, and team sometimes avoids
extra rejection paths.

PR-#13748
PR-#13075

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The EOF path returns Ok(None) before any UTF-8 conversion, while UTF-8 validation occurs only when
a separator is found. EnvLockfile::read treats None as “no env document”, so a
malformed/unterminated env doc with invalid bytes can be silently treated as absent instead of
failing the read.

pnpm/crates/lockfile/src/yaml_documents.rs[90-141]
pnpm/crates/lockfile/src/env_lockfile.rs[115-124]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`read_first_yaml_document_in_chunks()` returns `Ok(None)` on EOF even if it has accumulated non-empty bytes (including bytes after a valid `---\n` prefix) and those bytes are not valid UTF-8. Because UTF-8 validation only happens on the “separator found” path (`String::from_utf8(content)`), a malformed/unterminated env document can mask lockfile corruption.

### Issue Context
Lockfiles are treated as attacker-controlled input in this repo. The pre-command path uses `EnvLockfile::read()` to decide whether to sync/repair the env lockfile; changing “corrupt lockfile” into “no env document” can lead to confusing behavior and different error reporting.

### Fix Focus Areas
- pnpm/crates/lockfile/src/yaml_documents.rs[108-134]

### Suggested fix approach
- When `read == 0` (EOF):
 - If `withheld_carriage_return` is true, flush it into `content` (push `b'\r'`) so normalization doesn’t drop the last byte.
 - If `content` is non-empty, validate it as UTF-8 (e.g., `std::str::from_utf8(&content)`), and if invalid return `io::ErrorKind::InvalidData`.
 - Then return `Ok(None)`.
- Add a regression unit test covering invalid UTF-8 before EOF **without** a separator (e.g., `---\nfoo: <invalid bytes>` with EOF) expecting `InvalidData`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Copilot AI review requested due to automatic review settings August 11, 2026 09:08
@greptile-apps
greptile-apps Bot dismissed their stale review August 11, 2026 09:08

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan

zkochan commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

Qodo findings from the latest run — neither is being changed:

1. "Changeset missing pnpm entry" — this is what the repo asks for. AGENTS.md ("Changesets for the Rust products"): "Do not add "pnpm" to a Rust-only changeset: in changesets, pnpm always means the TypeScript CLI package. A changeset whose implementation is Rust-only and targets pacquet must omit "pnpm"." This PR is Rust-only, so the changeset targets pacquet alone.

2. "Invalid UTF-8 ignored" — the observation is accurate but the outcome is right. The env-document read now validates UTF-8 only for the bytes it returns; a file with no closing \n---\n yields Ok(None), which is the truthful answer to "does this lockfile carry an env document" regardless of what the undecodable bytes are. Corruption still surfaces: Lockfile::load_wanted_from_dir reads the file whole with fs::read_to_string (load_lockfile.rs:104), so an unreadable lockfile fails there, where the error names the right thing. The TypeScript counterpart is more lenient still — streamReadFirstYamlDocument decodes through StringDecoder, which substitutes U+FFFD and never errors.


Written by an agent (Claude Code, claude-opus-5).

@qodo-code-review

Copy link
Copy Markdown

Qodo findings from the latest run — neither is being changed:

1. "Changeset missing pnpm entry" — this is what the repo asks for. AGENTS.md ("Changesets for the Rust products"): "Do not add "pnpm" to a Rust-only changeset: in changesets, pnpm always means the TypeScript CLI package. A changeset whose implementation is Rust-only and targets pacquet must omit "pnpm"." This PR is Rust-only, so the changeset targets pacquet alone.

2. "Invalid UTF-8 ignored" — the observation is accurate but the outcome is right. The env-document read now validates UTF-8 only for the bytes it returns; a file with no closing \n---\n yields Ok(None), which is the truthful answer to "does this lockfile carry an env document" regardless of what the undecodable bytes are. Corruption still surfaces: Lockfile::load_wanted_from_dir reads the file whole with fs::read_to_string (load_lockfile.rs:104), so an unreadable lockfile fails there, where the error names the right thing. The TypeScript counterpart is more lenient still — streamReadFirstYamlDocument decodes through StringDecoder, which substitutes U+FFFD and never errors.


Written by an agent (Claude Code, claude-opus-5).

Understood. Based on the repository guidance and the implementation context:

  • finding 1 is not applicable: this is a Rust-only change targeting pacquet, and the changeset correctly omits pnpm.
  • finding 2 is technically accurate but not actionable here: the streaming helper only needs to determine whether a complete env document exists, while full lockfile loading still validates the entire file. The behavior is also consistent with the more lenient TypeScript implementation.

No code changes are needed for either finding.

greptile-apps[bot]
greptile-apps Bot previously approved these changes Aug 11, 2026
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 174f88f

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Logging every comparison dumped the 150 KB fixture once per chunk size on
a passing run, which buries the one comparison a reader needs when it
fails. Log both documents from the failing comparison instead.
Copilot AI review requested due to automatic review settings August 11, 2026 09:14
@greptile-apps
greptile-apps Bot dismissed their stale review August 11, 2026 09:14

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan

zkochan commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

On the latest Qodo run: findings 1 and 2 are the same two settled above — the changeset is Rust-only by design, and the UTF-8 behavior is intentional.

Finding 3 ("verbose test logging") is fixed in 25bf6ec. The unconditional logging came from a CodeRabbit nitpick asking for the style guide's eprintln!-before-assert_eq! rule for multiline values; taken literally it dumped the 150 KB fixture once per chunk size on every passing run. assert_documents_eq now logs both documents only for the comparison that actually fails, which is what the rule is for — assert_eq! renders a multiline document as one escaped line, so the readable form is still there when it matters:

chunk size 1
READ:
lockfileVersion: env-1.0
importers:
  .:
    foo: bar

EXPECTED:
lockfileVersion: env-1.0
importers:
  .:
    foo:

Written by an agent (Claude Code, claude-opus-5).

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 25bf6ec

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@zkochan

zkochan commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

On the micro-benchmark numbers: lockfile/parse_pnpm_lock (1.18x) and workspace_resolution/hoist_heavy (1.30x) are runner noise, not this change.

  • Neither benchmark reaches the changed code. EnvLockfile::read / read_first_yaml_document are not referenced anywhere in pnpm/tasks/micro-benchmark/; parse_pnpm_lock goes through Lockfile::load_*, whose whole-file fs::read_to_string this PR does not touch, and hoist_heavy is pure in-memory resolution.
  • The same job reported the opposite sign earlier on this branch: lockfile/parse_pnpm_lock was 1.03 14.4±1.60ms on main vs 1.00 14.0±0.58ms on the PR — the PR faster — with no change to that path in between.
  • The same table has tarball/download_dependency at 1.32x in the PR's favour, which this change cannot cause either.

Happy to re-run the benchmark job if a maintainer wants a second sample.


Written by an agent (Claude Code, claude-opus-5).

@github-actions

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 25bf6ec3f07a

Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm. Bencher consumes pacquet@HEAD and pnpr@HEAD.

The tables below show mean ± σ; Bencher thresholds on the minimum latency, which is far less perturbed by shared-runner contention (noise only adds time).

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.987 ± 0.201 2.673 3.318 1.91 ± 0.22
pacquet@main 2.606 ± 0.173 2.386 2.867 1.67 ± 0.19
pnpr@HEAD 1.593 ± 0.163 1.378 1.821 1.02 ± 0.14
pnpr@main 1.563 ± 0.145 1.387 1.815 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.98676857014,
      "stddev": 0.20062437409103143,
      "median": 2.9840695244399997,
      "user": 3.1786229199999996,
      "system": 2.4089758799999994,
      "min": 2.67254880044,
      "max": 3.31840489944,
      "times": [
        3.31840489944,
        3.16000284644,
        2.95665873844,
        3.00554209044,
        3.04114254044,
        2.96259695844,
        2.67254880044,
        2.72112233144,
        3.16744616244,
        2.86222033344
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.6057062228400003,
      "stddev": 0.17274701573391962,
      "median": 2.56939587094,
      "user": 2.05351962,
      "system": 1.5220825799999997,
      "min": 2.38608628144,
      "max": 2.86711077844,
      "times": [
        2.84638729144,
        2.55208070644,
        2.58671103544,
        2.45318722444,
        2.4630607214399998,
        2.46394888844,
        2.38608628144,
        2.74529995544,
        2.69318934544,
        2.86711077844
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5928890232400001,
      "stddev": 0.16333094111308916,
      "median": 1.5699131454400002,
      "user": 1.1891808199999998,
      "system": 1.25777908,
      "min": 1.37767891744,
      "max": 1.8207382164400001,
      "times": [
        1.44804471544,
        1.77491459144,
        1.8207382164400001,
        1.58453841344,
        1.6800465684399999,
        1.44229657544,
        1.45802563744,
        1.55528787744,
        1.37767891744,
        1.78731871944
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.5631573690400002,
      "stddev": 0.1454758566400991,
      "median": 1.53131773794,
      "user": 1.2178540199999999,
      "system": 1.21238758,
      "min": 1.3873060984399999,
      "max": 1.8154292334400002,
      "times": [
        1.8154292334400002,
        1.69658705244,
        1.7161943984399999,
        1.3873060984399999,
        1.44407549744,
        1.49902223344,
        1.6195794344399999,
        1.56361324244,
        1.49599806444,
        1.39376843544
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 279.2 ± 38.4 239.7 351.3 1.00
pacquet@main 287.8 ± 15.0 259.0 313.8 1.03 ± 0.15
pnpr@HEAD 309.9 ± 11.1 290.5 329.0 1.11 ± 0.16
pnpr@main 392.7 ± 25.7 348.8 424.0 1.41 ± 0.21
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.2792104924,
      "stddev": 0.038401094008801435,
      "median": 0.26972685040000005,
      "user": 0.23035690000000003,
      "system": 0.55960246,
      "min": 0.2397435384,
      "max": 0.35127905940000004,
      "times": [
        0.26652258940000007,
        0.2590177584,
        0.27293111140000004,
        0.2466993594,
        0.24018973640000002,
        0.2397435384,
        0.28214310840000006,
        0.33259416740000003,
        0.35127905940000004,
        0.30098449540000005
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.2878035236,
      "stddev": 0.015029595217456608,
      "median": 0.29018921090000005,
      "user": 0.2493768,
      "system": 0.55594376,
      "min": 0.2589575344,
      "max": 0.3137873144000001,
      "times": [
        0.29712779440000003,
        0.3137873144000001,
        0.2898778114,
        0.29678666440000007,
        0.29190688040000007,
        0.27218780540000004,
        0.28834857040000006,
        0.27855425040000004,
        0.2905006104,
        0.2589575344
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.30986929420000003,
      "stddev": 0.011134005166199076,
      "median": 0.3119235709,
      "user": 0.2624307,
      "system": 0.5832982600000001,
      "min": 0.29054647640000003,
      "max": 0.32903248840000004,
      "times": [
        0.31057425240000003,
        0.30432174240000004,
        0.30951345040000006,
        0.29054647640000003,
        0.2947824304000001,
        0.31736573440000004,
        0.31327288940000003,
        0.31346925740000003,
        0.31581422040000007,
        0.32903248840000004
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.3927285408000001,
      "stddev": 0.025683025950549176,
      "median": 0.3964017839,
      "user": 0.3624123,
      "system": 0.73389546,
      "min": 0.34883441940000004,
      "max": 0.42401548240000003,
      "times": [
        0.34883441940000004,
        0.4016577424000001,
        0.3521640214,
        0.38904015140000003,
        0.40327692340000004,
        0.4238907874000001,
        0.39114582540000004,
        0.42401548240000003,
        0.4060341894000001,
        0.38722586540000004
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.747 ± 0.078 2.681 2.902 1.72 ± 0.14
pacquet@main 2.701 ± 0.061 2.646 2.845 1.69 ± 0.14
pnpr@HEAD 1.679 ± 0.174 1.458 1.885 1.05 ± 0.14
pnpr@main 1.595 ± 0.126 1.474 1.820 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.74717683806,
      "stddev": 0.07763094774616573,
      "median": 2.70861746196,
      "user": 1.9851908199999997,
      "system": 1.6549877999999996,
      "min": 2.68149446696,
      "max": 2.9018510149599996,
      "times": [
        2.68245822996,
        2.70945670296,
        2.70180063496,
        2.77422933696,
        2.70777822096,
        2.9018510149599996,
        2.76267060496,
        2.85944345696,
        2.6905857109599998,
        2.68149446696
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.70149392316,
      "stddev": 0.06130370966509728,
      "median": 2.67630175446,
      "user": 1.9546095199999995,
      "system": 1.5736736,
      "min": 2.6459806479599997,
      "max": 2.84479172796,
      "times": [
        2.65940183396,
        2.66214791196,
        2.6459806479599997,
        2.6824186229599998,
        2.67018488596,
        2.6648170949599996,
        2.69768086696,
        2.7262772539599998,
        2.84479172796,
        2.76123838496
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.6785069486600002,
      "stddev": 0.17402828692267122,
      "median": 1.7530483969600001,
      "user": 1.18331162,
      "system": 1.2880468999999999,
      "min": 1.4576986279600002,
      "max": 1.8853987319600003,
      "times": [
        1.5046329559600002,
        1.49572136796,
        1.8753337739600002,
        1.7366009769600002,
        1.7694958169600001,
        1.79786263796,
        1.4576986279600002,
        1.7864778509600001,
        1.47584674596,
        1.8853987319600003
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.59501384586,
      "stddev": 0.12645648936868825,
      "median": 1.5326346069600003,
      "user": 1.25863762,
      "system": 1.3920952,
      "min": 1.4738831649600002,
      "max": 1.82042698496,
      "times": [
        1.4738831649600002,
        1.4961237549600002,
        1.5422502739600001,
        1.69813125396,
        1.49675208496,
        1.6775995379600002,
        1.5230189399600003,
        1.82042698496,
        1.7395693719600003,
        1.4823830909600002
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 438.0 ± 17.5 418.8 463.2 1.31 ± 0.08
pacquet@main 440.5 ± 20.6 414.9 473.4 1.32 ± 0.09
pnpr@HEAD 334.7 ± 14.9 319.3 370.0 1.00
pnpr@main 335.1 ± 9.2 323.4 350.7 1.00 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.43802837732000005,
      "stddev": 0.017535130266074127,
      "median": 0.43030658872000005,
      "user": 0.56886332,
      "system": 0.7454495,
      "min": 0.41875999872,
      "max": 0.46319446072000003,
      "times": [
        0.41878037572000004,
        0.41875999872,
        0.43347809072000004,
        0.45215551872000004,
        0.46319446072000003,
        0.46287564172,
        0.45098996972000005,
        0.42713508672000006,
        0.42670832672000003,
        0.42620630372
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.4404896159200001,
      "stddev": 0.020618793794719117,
      "median": 0.43565630772,
      "user": 0.58454462,
      "system": 0.7400635999999999,
      "min": 0.41492430472,
      "max": 0.47344379072000004,
      "times": [
        0.47344379072000004,
        0.41629852472,
        0.41492430472,
        0.44906546472000003,
        0.42504791872000003,
        0.45615852772000004,
        0.46857275272000004,
        0.43553664172,
        0.43577597372000004,
        0.43007225972
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.33470932272000004,
      "stddev": 0.01493196632996838,
      "median": 0.33203194872,
      "user": 0.24773041999999995,
      "system": 0.5506024,
      "min": 0.31925804972000005,
      "max": 0.36996547572000005,
      "times": [
        0.31977779872,
        0.31925804972000005,
        0.32927118272,
        0.32993111572,
        0.32366246672000004,
        0.34490858172000005,
        0.33413278172000005,
        0.33847501172000005,
        0.33771076272,
        0.36996547572000005
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.33512574612,
      "stddev": 0.009198203204498613,
      "median": 0.33604139772,
      "user": 0.24295231999999997,
      "system": 0.5637769999999999,
      "min": 0.32343491772000005,
      "max": 0.35067357272000005,
      "times": [
        0.34254824572000003,
        0.32343491772000005,
        0.34028644472,
        0.34155521472,
        0.35067357272000005,
        0.32752861972,
        0.34054425872000005,
        0.32408772772,
        0.33179635072,
        0.32880210872000004
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.809 ± 0.035 1.776 1.862 5.37 ± 0.21
pacquet@main 1.796 ± 0.026 1.775 1.859 5.33 ± 0.20
pnpr@HEAD 0.337 ± 0.012 0.313 0.353 1.00
pnpr@main 0.353 ± 0.019 0.328 0.382 1.05 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.8089458829199998,
      "stddev": 0.03536153997733935,
      "median": 1.78979671552,
      "user": 0.9341970399999999,
      "system": 0.9352794999999998,
      "min": 1.77553357602,
      "max": 1.8620057330200002,
      "times": [
        1.77553357602,
        1.7873044240200002,
        1.7769808550200001,
        1.7781525950200001,
        1.7922890070200002,
        1.8548470470200003,
        1.78513799602,
        1.8479179430200001,
        1.8620057330200002,
        1.82928965302
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.79627182732,
      "stddev": 0.025647256815049604,
      "median": 1.7883329245200001,
      "user": 0.9378249399999999,
      "system": 0.8679767999999999,
      "min": 1.7747640660200001,
      "max": 1.85934041702,
      "times": [
        1.80028683902,
        1.78818940702,
        1.8182724810200002,
        1.85934041702,
        1.78573713102,
        1.77824794502,
        1.79336174102,
        1.7884764420200001,
        1.7760418040200001,
        1.7747640660200001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.33691408072,
      "stddev": 0.011684533058300625,
      "median": 0.34010140252000004,
      "user": 0.24499304,
      "system": 0.5707513000000001,
      "min": 0.31313337402,
      "max": 0.35282017202000004,
      "times": [
        0.34444117802,
        0.34273619402000005,
        0.35282017202000004,
        0.32968735802000004,
        0.32986772802000003,
        0.31313337402,
        0.32828399202,
        0.34073878902000004,
        0.33946401602000004,
        0.34796800602000005
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.35339914802000005,
      "stddev": 0.018940356682277462,
      "median": 0.35195861902000003,
      "user": 0.26027524,
      "system": 0.5870008999999999,
      "min": 0.32815323602,
      "max": 0.38155152002000003,
      "times": [
        0.32815323602,
        0.34777013302000004,
        0.33165926302000004,
        0.36108249902,
        0.33563982302,
        0.38155152002000003,
        0.35614710502,
        0.38082970402000005,
        0.36425362802000005,
        0.34690456902000005
      ]
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 274.0 ± 18.8 242.0 306.7 2.93 ± 0.21
pacquet@main 246.5 ± 20.4 219.6 283.5 2.63 ± 0.23
pnpr@HEAD 98.5 ± 4.8 91.6 110.6 1.05 ± 0.06
pnpr@main 93.6 ± 2.3 90.4 98.5 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.2740026633,
      "stddev": 0.018836609820814698,
      "median": 0.27713426560000004,
      "user": 0.24947934,
      "system": 0.07590316,
      "min": 0.2419875601,
      "max": 0.30669990410000003,
      "times": [
        0.30669990410000003,
        0.28810518510000005,
        0.28283649410000006,
        0.2419875601,
        0.2609050861,
        0.27837722610000004,
        0.28512758010000006,
        0.26762757810000004,
        0.27589130510000004,
        0.25246871410000005
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.24649836128181815,
      "stddev": 0.020440251877844852,
      "median": 0.2416080571,
      "user": 0.22065668545454545,
      "system": 0.08418226909090909,
      "min": 0.2195911681,
      "max": 0.28350111310000004,
      "times": [
        0.25878497110000004,
        0.28350111310000004,
        0.2384286431,
        0.2371522951,
        0.2195911681,
        0.2416080571,
        0.2249975771,
        0.2559840191,
        0.2311289561,
        0.24288792210000001,
        0.2774172521
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.09854811009999999,
      "stddev": 0.004837720515582572,
      "median": 0.09664490410000001,
      "user": 0.027812243448275854,
      "system": 0.011850222068965518,
      "min": 0.09163683310000001,
      "max": 0.1106275371,
      "times": [
        0.0957740371,
        0.10600779610000001,
        0.1028125431,
        0.09655953310000001,
        0.0999804521,
        0.10160631510000001,
        0.09765488110000001,
        0.09440694810000001,
        0.10615642510000001,
        0.09761899410000001,
        0.09643010010000001,
        0.09408307010000001,
        0.0968712481,
        0.09664490410000001,
        0.0958536271,
        0.0955189981,
        0.0994835981,
        0.10232538710000001,
        0.1106275371,
        0.1103119441,
        0.10019822110000001,
        0.0950120651,
        0.0964510291,
        0.0926183971,
        0.0957482691,
        0.09163683310000001,
        0.0992018491,
        0.0958812691,
        0.09441892110000001
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.09357883089310344,
      "stddev": 0.002300534742639964,
      "median": 0.0928388021,
      "user": 0.02472127793103448,
      "system": 0.01126832551724138,
      "min": 0.0904337731,
      "max": 0.0984749221,
      "times": [
        0.0965729681,
        0.0938423381,
        0.0915648891,
        0.09154286710000001,
        0.09309271910000001,
        0.0928388021,
        0.09623479310000001,
        0.09683112410000001,
        0.0946524301,
        0.09271869610000001,
        0.09118686810000001,
        0.0917904821,
        0.09179460010000001,
        0.0959033501,
        0.09253561210000001,
        0.0914025331,
        0.09103355010000001,
        0.09130457010000001,
        0.0904337731,
        0.09086505310000001,
        0.09404465810000001,
        0.09493580210000001,
        0.09577013910000001,
        0.09807522210000001,
        0.0984749221,
        0.09530670910000001,
        0.0921840921,
        0.0923351961,
        0.0945173361
      ]
    }
  ]
}

Scenario: Isolated linker: peer-heavy resolve, hot cache, offline

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.284 ± 0.360 0.790 2.111 1.01 ± 0.36
pacquet@main 1.268 ± 0.278 0.873 1.762 1.00
pnpm@HEAD 3.438 ± 0.202 3.140 3.716 2.71 ± 0.62
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.2843089573533335,
      "stddev": 0.3604455549931562,
      "median": 1.2768491990200002,
      "user": 1.2916758644444446,
      "system": 0.18727625999999997,
      "min": 0.7901901570200001,
      "max": 2.11074932802,
      "times": [
        1.33835227702,
        1.2389852810200002,
        1.15456070002,
        0.7901901570200001,
        0.9953656550200001,
        2.11074932802,
        1.2768491990200002,
        1.3670861340200002,
        1.28664188502
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.2681776815755557,
      "stddev": 0.27796327155696904,
      "median": 1.2048073220200002,
      "user": 1.292848308888889,
      "system": 0.17409114888888888,
      "min": 0.87266319002,
      "max": 1.76239428702,
      "times": [
        1.76239428702,
        1.1017381590200002,
        1.2048073220200002,
        0.87266319002,
        1.32853812102,
        1.6349365740200001,
        1.27869294402,
        1.1301388090200002,
        1.0996897280200002
      ]
    },
    {
      "command": "pnpm@HEAD",
      "mean": 3.4380317512422223,
      "stddev": 0.20178354586003697,
      "median": 3.54574312702,
      "user": 5.348600531111111,
      "system": 0.30117603777777774,
      "min": 3.13993136102,
      "max": 3.71639357302,
      "times": [
        3.71639357302,
        3.54574312702,
        3.21867455302,
        3.13993136102,
        3.33527974902,
        3.2604304910199997,
        3.60169458902,
        3.56006110502,
        3.56407721302
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.525 ± 0.104 4.446 4.723 1.25 ± 0.05
pacquet@main 4.645 ± 0.207 4.437 5.133 1.28 ± 0.07
pnpr@HEAD 3.634 ± 0.118 3.501 3.914 1.00
pnpr@main 3.846 ± 0.092 3.729 4.035 1.06 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.5249879019399994,
      "stddev": 0.10371141465888725,
      "median": 4.47670132804,
      "user": 1.9953441199999997,
      "system": 1.5516316399999999,
      "min": 4.44620023104,
      "max": 4.7227054630400005,
      "times": [
        4.51530541404,
        4.50574107004,
        4.7227054630400005,
        4.71299289004,
        4.47303933104,
        4.44620023104,
        4.46317545404,
        4.46133951504,
        4.48036332504,
        4.46901632604
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.6447610919399995,
      "stddev": 0.20680890084696732,
      "median": 4.580176310040001,
      "user": 2.23679142,
      "system": 1.6313243399999997,
      "min": 4.4371145080400005,
      "max": 5.13307320804,
      "times": [
        4.73527756104,
        4.49605244204,
        4.57370529804,
        4.4371145080400005,
        4.51477841404,
        4.78000782004,
        4.58664732204,
        4.48460595604,
        4.7063483900400005,
        5.13307320804
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.6342397909399997,
      "stddev": 0.11798892900790195,
      "median": 3.61826190304,
      "user": 1.5984800200000002,
      "system": 1.60422734,
      "min": 3.50094515304,
      "max": 3.91428609804,
      "times": [
        3.50094515304,
        3.59334658304,
        3.91428609804,
        3.65211245204,
        3.53299704804,
        3.53437661004,
        3.63143228504,
        3.6050915210400003,
        3.68387685604,
        3.69393330304
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.84582459824,
      "stddev": 0.09153055844996541,
      "median": 3.8354416985400004,
      "user": 2.17699402,
      "system": 2.15536674,
      "min": 3.72881788704,
      "max": 4.03481091704,
      "times": [
        3.81938431904,
        3.7572994410400002,
        3.72881788704,
        3.8514990780400002,
        3.81832335704,
        3.7645545680400003,
        3.93887827604,
        3.8724806050400002,
        3.87219753404,
        4.03481091704
      ]
    }
  ]
}

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13820
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
2,681.49 ms
(-0.26%)Baseline: 2,688.48 ms
3,226.17 ms
(83.12%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,775.53 ms
(-2.23%)Baseline: 1,815.99 ms
2,179.19 ms
(81.48%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
418.76 ms
(-9.94%)Baseline: 464.98 ms
557.98 ms
(75.05%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
241.99 ms
(+3.62%)Baseline: 233.54 ms
280.25 ms
(86.35%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,672.55 ms
(+9.05%)Baseline: 2,450.77 ms
2,940.93 ms
(90.87%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,446.20 ms
(-2.08%)Baseline: 4,540.65 ms
5,448.78 ms
(81.60%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
239.74 ms
(-19.93%)Baseline: 299.42 ms
359.30 ms
(66.73%)
isolated-linker.peer-heavy-resolve.hot-cache.offline📈 view plot
🚷 view threshold
790.19 ms
(+5.82%)Baseline: 746.75 ms
896.10 ms
(88.18%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13820
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,457.70 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
313.13 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
319.26 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
91.64 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,377.68 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,500.95 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
290.55 ms
🐰 View full continuous benchmarking report in Bencher

@zkochan

zkochan commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

Same for the integrated report (pacquet@HEAD 2.99s vs pacquet@main 2.61s on the cold-cache isolated-linker scenario): shared-runner contention, and both Bencher reports are green — no threshold alert on the minimum latency they gate on.

Mechanically it cannot be this change. That scenario is a full cold install; EnvLockfile::read runs a handful of times in it, and on the benchmark's small fixture lockfile the difference between the old whole-file read and the new bounded one is single-digit microseconds. There is no path in this diff that can account for ~380ms.


Written by an agent (Claude Code, claude-opus-5).

@zkochan
zkochan merged commit 1c7ad81 into main Aug 11, 2026
34 checks passed
@zkochan
zkochan deleted the perf-13819 branch August 11, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pacquet reads the whole pnpm-lock.yaml on every command to get the env document

3 participants