Skip to content

perf: skip per-component canonicalization inside node_modules #1202

Description

@Boshen

Why

Canonicalizing a resolved path today walks every component, calling read_link / lstat per segment. That is slow, and most of it is wasted work: by package-manager convention nothing below a <...>/node_modules/<pkg>/ directory (the "anchor") is a symlink. This holds for every layout — flat, isolated (pnpm .pnpm/, yarn .store/, bun .bun/), hoisted, PnP — because even when the top-level <pkg> is a symlink into a virtual store, the dereferenced target is again shaped node_modules/<pkg>/... with real, non-symlink files below it.

Idea

Find the deepest node_modules/<pkg> anchor by walking the cached parent chain (allocation-free, no syscalls). Canonicalize the anchor properly (so a symlinked project root / junction / linked workspace package is still resolved), then append the suffix below it without a per-component read_link walk — verifying via cache-hit lstats that the suffix is symlink-free, and falling back to the normal walk otherwise.

Measured impact

Prototyped in #1189 and #1179: ~16-40% fewer filesystem syscalls across all npm/pnpm/yarn/bun × flat/isolated/hoisted/pnp combos.

Refs #1189, #1179.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions