Skip to content

feat(workspace): parse pnpm-workspace.yaml once and expose pmOnFail - #1064

Open
fengmk2 wants to merge 2 commits into
mainfrom
perf/reuse-pnpm-workspace-yaml
Open

fengmk2 wants to merge 2 commits into
mainfrom
perf/reuse-pnpm-workspace-yaml

Conversation

@fengmk2

@fengmk2 fengmk2 commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Motivation

Vite+ reads pmOnFail from pnpm-workspace.yaml to choose the pnpm version that vp --version reports (voidzero-dev/vite-plus#3697). For that, it parses the file again with its own serde_norway dependency. find_workspace_root already holds the file bytes, and a lookup from a member package has already parsed them for the member globs. load_package_graph then parses the same file a third time.

WorkspaceFile::PnpmWorkspaceYaml now holds a PnpmWorkspaceFile, which keeps the file bytes with a parse result that is filled on first use (OnceCell). Member lookup, load_package_graph, and the new pm_on_fail() accessor share that one parse. A lookup from the workspace root still skips the parse, and each find_workspace_root call reads the file again, so it sees later edits.

pm_on_fail() returns the raw string and leaves its meaning to the caller. A missing or non-string value reads as None, so it cannot break member lookup. PnpmWorkspaceFile keeps content() and path(), and From<FileWithPath> builds one, so callers that match the variant or read its bytes still compile.

WorkspaceFile::PnpmWorkspaceYaml now holds a PnpmWorkspaceFile, which
keeps the file bytes with a parse result that is filled on first use.
Member lookup, load_package_graph, and the new pm_on_fail() accessor
share that one parse. A lookup from the workspace root still skips the
parse, and each find_workspace_root call reads the file again.

pm_on_fail() returns the raw pmOnFail string. A missing or non-string
value reads as None, so it cannot break member lookup.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

fspy benchmark

linux

dynamic/launch             change  -0.24%  [ -2.78% ..  +2.21%]  overhead   +53.76%
dynamic/access             change  -0.85%  [ -3.64% ..  +3.90%]  overhead   +21.24%
dynamic/access-relative    change  +0.00%  [ -2.14% ..  +2.20%]  overhead   +66.33%
dynamic/access-contended   change  +0.93%  [ -3.84% ..  +5.31%]  overhead    +6.84%
static/launch              change  +0.02%  [ -2.62% ..  +2.81%]  overhead  +203.42%
static/access              change  +0.23%  [ -0.70% ..  +0.86%]  overhead +1433.98%
static/access-relative     change  +0.90%  [ -0.48% ..  +2.05%]  overhead +1930.63%
static/access-contended    change  +0.44%  [ -1.46% ..  +1.59%]  overhead +1691.19%

macos

dynamic/launch             change  -0.21%  [ -2.80% ..  +2.74%]  overhead  +223.11%
dynamic/access             change  +0.00%  [ -1.61% ..  +1.66%]  overhead    +4.93%
dynamic/access-relative    change  +0.26%  [ -3.70% ..  +3.57%]  overhead  +272.73%
dynamic/access-contended   change  +0.10%  [ -2.89% ..  +2.02%]  overhead    +3.05%

windows

dynamic/launch             change  -0.23%  [ -2.99% ..  +3.20%]  overhead   +26.77%
dynamic/access             change  +0.18%  [ -1.24% ..  +1.09%]  overhead    +1.27%
dynamic/access-relative    change  +0.00%  [ -0.73% ..  +0.73%]  overhead    +1.29%
dynamic/access-contended   change  +0.18%  [ -0.53% ..  +0.88%]  overhead    +1.61%

@fengmk2
fengmk2 marked this pull request as draft December 6, 2026 08:32
@fengmk2
fengmk2 marked this pull request as ready for review December 6, 2026 08:35
@fengmk2
fengmk2 requested a review from wan9chi December 6, 2026 08:35
Use once_cell's OnceCell::get_or_try_init for the lazy parse, as vt
already does, so the parse lives in PnpmWorkspaceFile::parsed().
WorkspaceMemberGlobs owns its globs again, and the tests check the
cache state directly in place of a test-only parse counter.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
fengmk2 added a commit to voidzero-dev/vite-plus that referenced this pull request Dec 6, 2026
Windows treats PNPM_CONFIG_PM_ON_FAIL and pnpm_config_pm_on_fail as one
variable, so clearing the lowercase name after setting the uppercase one
removed the policy. Also moves the vite-task pin to 2d01e63e, the
current head of voidzero-dev/vite-task#1064.
@fengmk2

fengmk2 commented Dec 6, 2026

Copy link
Copy Markdown
Member Author

Benchmark of main (0455423a) against this PR (2d01e63e): release build on macOS, a 20-package workspace, and vite-plus's own pnpm-workspace.yaml (181 lines, 4.4 KB). Each value is the median of 15 batches, averaged over two alternating runs.

Operation main This PR YAML parses
Parse pnpm-workspace.yaml once 64 µs 65 µs 1 → 1
find_workspace_root from the root 10 µs 10 µs 0 → 0
find_workspace_root from a member 127 µs 127 µs 1 → 1
Root lookup + load_package_graph 764 µs 730 µs 1 → 1 (difference is noise)
Member lookup + load_package_graph 843 µs 786 µs 2 → 1

The saving matches one parse. With a 3-line pnpm-workspace.yaml, one parse takes about 2 µs, so the difference is below the run-to-run noise of about ±40 µs on the load_package_graph rows.

This branch has not been deployed

No deployments
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