Skip to content

Windows perf: memoize norm_case to avoid repeated GetLongPathNameW syscalls during refresh #455

@eleanorjboyd

Description

@eleanorjboyd

Summary

norm_case on Windows wraps GetLongPathNameW, which requires the path to exist on disk to normalize it — i.e., every call is a filesystem lookup that Defender can intercept. It is invoked from many hot paths during refresh and on inputs that repeat (the user home alone is normalized many times per refresh). Death-by-a-thousand-cuts under Defender that compounds with #453 and #454.

Note: prior audit issue #278 closed without a memoization layer being added. This issue is specifically about adding a per-process cache + auditing redundant call sites, not re-doing the audit.

Full investigation: docs/windows-perf-investigation.md (Issue 3).

Where

Hot call sites include:

Proposed fix

  1. Add per-process memoization for norm_case keyed on the input path. A simple RwLock<HashMap<PathBuf, PathBuf>> would eliminate repeat syscalls. The user home, common parents, and PATH entries are normalized many times per refresh.
  2. Audit call sites and skip norm_case for paths already known to be canonical (e.g., paths already produced by GetLongPathNameW, or built entirely from already-normalized components).

Estimated change size: ~50 lines for memoization.

Why this isn't covered by #278

#278 was a higher-level audit of norm_case responsibilities. It did not introduce a result cache, and the syscall density on Windows refresh paths remains a measurable cost. This issue tracks the concrete memoization + redundant-call removal.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions