refactor: refactor utf8 path conversions#219
Merged
Merged
Conversation
Merging this PR will improve performance by 5.3%
Performance Changes
Tip Curious why this is faster? Comment Comparing |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors path-to-string conversion to use strict UTF-8 handling instead of lossy conversion across resolver internals, tsconfig handling, filesystem code, NAPI output, and tests.
Changes:
- Adds a shared
path_to_strhelper for strict UTF-8 path assertions. - Replaces
to_string_lossy()conversions withto_str().expect(...)orpath_to_str(...). - Keeps extension and alias path construction on borrowed UTF-8 strings where possible.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/path.rs |
Adds the shared strict UTF-8 path conversion helper. |
src/lib.rs |
Applies strict path conversion in resolver tracing, alias, extension, and error construction paths. |
src/tsconfig.rs |
Uses strict conversion for tsconfig tracing and ${configDir} substitution. |
src/file_system.rs |
Uses strict UTF-8 conversion when rebuilding wasm symlink paths. |
napi/src/lib.rs |
Converts resolved paths to JS strings with strict UTF-8 handling. |
src/tests/alias.rs |
Updates alias tests to use strict path conversion. |
src/tests/browser_field.rs |
Updates browser field fallback path conversion. |
src/tests/memory_fs.rs |
Adds a local helper and uses strict paths for the in-memory filesystem. |
src/tests/missing.rs |
Updates alias path setup to strict conversion. |
src/tests/pnp.rs |
Updates PnP path assertions and formatting to strict conversion. |
src/tests/resolve.rs |
Updates fixture path conversion to strict UTF-8. |
src/tests/roots.rs |
Updates absolute path requests to strict UTF-8. |
src/tests/windows.rs |
Updates Windows path assertions to strict UTF-8. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
stormslowly
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Rspack support UTF8 only Path so it's not necessary for rspack-resolver to support non utf8-path
path_to_strhelper for core path assertions.Why
rspack-resolver only needs to support UTF-8 paths, so lossy conversions can silently hide invalid path data and add unnecessary conversion work.
Performance notes
CodSpeed reports this PR improves three resolver benchmarks:
resolver[multi-thread]resolver[resolve from symlinks multi thread]resolver[resolve from symlinks]Local callgrind comparison for
resolver/resolve from symlinks(8975e38->85e0cec) shows the same direction:IrDrDwThe main reason is removing the
core::str::lossy::Utf8Chunks::nexthot path from repeatedto_string_lossy()calls. In the base profile it accounts for about52.5M Ir; after this PR it is replaced by cheaper strict UTF-8 validation (core::str::converts::from_utf8, about7.7M Ir). The affected hot paths are primarilyload_extensionsandload_alias_or_file, where resolver candidate paths are converted repeatedly.Measurement command shape:
Validation
cargo fmt --all --checkcargo check --workspacecargo check --workspace --features enable_instrumentcargo clippy --all-features -- -D warningscargo test -p rspack_resolver --lib -- --skip pnpFull
cargo test --workspacewas also run locally. It still fails on existing environment-sensitive fixtures: PnP tests needfixtures/pnp/.pnp.cjs, and integration resolve tests need local pnpm node_modules content.