Skip to content

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

Merged
elinor-fung merged 3 commits intodotnet:mainfrom
elinor-fung:deps-dir-sep
Mar 19, 2026
Merged

Remove redundant directory separator normalization in deps.json parsing#125251
elinor-fung merged 3 commits intodotnet:mainfrom
elinor-fung:deps-dir-sep

Conversation

@elinor-fung
Copy link
Member

@elinor-fung elinor-fung commented Mar 5, 2026

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.

@dotnet/appmodel @AaronRobinsonMSFT

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

Copilot AI review requested due to automatic review settings March 17, 2026 00:27
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


You can also share your feedback on Copilot code review. Take the survey.

@elinor-fung elinor-fung merged commit 02f7316 into dotnet:main Mar 19, 2026
173 of 177 checks passed
@elinor-fung elinor-fung deleted the deps-dir-sep branch March 19, 2026 17:23
@github-project-automation github-project-automation bot moved this to Done in AppModel Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants