Skip to content

Remove redundant directory separator normalization in deps.json parsing#125251

Open
elinor-fung wants to merge 2 commits intodotnet:mainfrom
elinor-fung:deps-dir-sep
Open

Remove redundant directory separator normalization in deps.json parsing#125251
elinor-fung wants to merge 2 commits intodotnet:mainfrom
elinor-fung:deps-dir-sep

Conversation

@elinor-fung
Copy link
Member

Normalize paths to the platform separator (DIR_SEPARATOR) once in the
deps_asset_t constructor instead of normalizing them to '/` to store them
and re-normalizing to platform separator on every use.

Removes >400 allocations on startup.

elinor-fung and others added 2 commits February 20, 2026 11:22
Normalize paths to the platform separator (DIR_SEPARATOR) once in the
deps_asset_t constructor instead of storing them with '/' and
re-normalizing on every use.

Previously:
- The constructor normalized '\\' -> '/' (canonical form)
- get_optional_path() normalized '/' -> DIR_SEPARATOR at parse time
  (for local_path, undone by the constructor)
- normalize_dir_separator() converted '/' -> DIR_SEPARATOR on every
  call to to_dir_path() and to_package_path(), allocating a new string
  each time

Now:
- The constructor normalizes directly to DIR_SEPARATOR (one allocation)
- normalize_dir_separator() is removed entirely
- get_deps_filename() is removed in favor of the equivalent get_filename()
- Placeholder checks updated to use DIR_SEPARATOR instead of hardcoded '/'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restructure to_dir_path to pass const references directly to to_path
when the relative path doesn't need modification (local_path set, or
runtimepack). This eliminates a string allocation per call in those
two fast paths.

Also fix 'helperthat' typo in deps_resolver.cpp comment.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 5, 2026 23:53
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @jeffschwMSFT, @elinor-fung
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes startup performance by normalizing directory separator characters in deps.json paths exactly once in the deps_asset_t constructor (to the platform's DIR_SEPARATOR), rather than normalizing from '/' to DIR_SEPARATOR on every access. This removes the normalize_dir_separator helper function and the get_deps_filename helper function, and updates placeholder detection and path-utility calls to work with already-platform-normalized paths.

Changes:

  • deps_entry.h: The deps_asset_t constructor now normalizes relative_path and local_path to DIR_SEPARATOR in place of the previous '/'-normalization
  • deps_entry.cpp: Removes normalize_dir_separator(), uses asset.relative_path directly, and refactors to_dir_path for clarity
  • deps_resolver.cpp: Removes get_deps_filename(), updates placeholder checks from "/_._" to DIR_SEPARATOR_STR "_._", and replaces get_deps_filename with get_filename

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/native/corehost/hostpolicy/deps_entry.h Constructor normalizes paths to platform separator once (instead of storing with '/' and converting on every use)
src/native/corehost/hostpolicy/deps_entry.cpp Removes normalize_dir_separator(), refactors to_dir_path to use pre-normalized paths, simplifies to_package_path
src/native/corehost/hostpolicy/deps_resolver.cpp Removes get_deps_filename(), fixes placeholder suffix check for platform-normalized paths

// Resources are represented as "lib/<netstandrd_ver>/<ietf-code>/<ResourceAssemblyName.dll>" in the deps.json.
// The <ietf-code> is the "directory" in the relative_path below, so extract it.
pal::string_t ietf_dir = get_directory(relative_path);
// runtimepack assets set the path to the local path - use relative_path as-is
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

The comment on line 138 is misleading and contradictory. It says "runtimepack assets set the path to the local path" but then says "use relative_path as-is". This is confusing because:

  1. If local_path was set for a runtimepack asset, we would have already returned on line 135.
  2. The code here reaches the runtimepack check only when local_path is empty.
  3. The original comment "runtimepack assets set the path to the local path" was a shorthand for "runtimepack stores the intended local path in the relative_path field", which is the opposite of what the comment reads now.

The comment should be clarified to indicate that for runtimepack entries with no local_path, relative_path is used as the full relative path (not just a filename, unlike other asset types).

Suggested change
// runtimepack assets set the path to the local path - use relative_path as-is
// For runtimepack assets without local_path, relative_path already contains the full relative path (not just the file name); use it as-is.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants