Remove redundant directory separator normalization in deps.json parsing#125251
Remove redundant directory separator normalization in deps.json parsing#125251elinor-fung wants to merge 2 commits intodotnet:mainfrom
Conversation
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>
|
Tagging subscribers to this area: @agocke, @jeffschwMSFT, @elinor-fung |
There was a problem hiding this comment.
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: Thedeps_asset_tconstructor now normalizesrelative_pathandlocal_pathtoDIR_SEPARATORin place of the previous'/'-normalizationdeps_entry.cpp: Removesnormalize_dir_separator(), usesasset.relative_pathdirectly, and refactorsto_dir_pathfor claritydeps_resolver.cpp: Removesget_deps_filename(), updates placeholder checks from"/_._"toDIR_SEPARATOR_STR "_._", and replacesget_deps_filenamewithget_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 |
There was a problem hiding this comment.
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:
- If
local_pathwas set for a runtimepack asset, we would have already returned on line 135. - The code here reaches the runtimepack check only when
local_pathis empty. - 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_pathfield", 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).
| // 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. |
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.