Skip to content

refactor(alias): compile fallback aliases once at construction#1264

Merged
Boshen merged 1 commit into
mainfrom
refactor/fallback-alias
Jul 2, 2026
Merged

refactor(alias): compile fallback aliases once at construction#1264
Boshen merged 1 commit into
mainfrom
refactor/fallback-alias

Conversation

@Boshen

@Boshen Boshen commented Jul 2, 2026

Copy link
Copy Markdown
Member

load_alias_by_options re-ran compile_alias (allocating and cloning every AliasValue) on every failed resolution, while the primary alias list is compiled once at construction. This compiles fallback once into a ResolverImpl.fallback field, uses load_alias directly at the fallback call site, and deletes load_alias_by_options (its only caller). compile_alias is pure over the post-sanitize options, so behavior is identical; with an empty fallback list the new field is an empty box + 32 zero bytes.

Also tidies clone_with_options while touching it: the (a && !b) || (!a && b) yarn_pnp cache check becomes a plain == comparison, and the stale #[allow(clippy::unused_self)] is removed (both cfg branches use self).

Split out of #1263.

`load_alias_by_options` re-ran `compile_alias` on every failed
resolution. Compile the fallback list once into a
`ResolverImpl.fallback` field, mirroring how `alias` is handled, and
delete the helper. Also simplify the yarn_pnp cache-reuse check in
`clone_with_options` to a plain equality and drop its stale
`#[allow(clippy::unused_self)]`.
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.83%. Comparing base (4837a2e) to head (807393e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1264      +/-   ##
==========================================
- Coverage   93.85%   93.83%   -0.02%     
==========================================
  Files          21       21              
  Lines        4313     4301      -12     
==========================================
- Hits         4048     4036      -12     
  Misses        265      265              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq

codspeed-hq Bot commented Jul 2, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚡ 2 improved benchmarks
❌ 1 regressed benchmark
✅ 18 untouched benchmarks
⏩ 5 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
pm/bun-flat 902.6 µs 935.7 µs -3.53%
pm/npm-flat 898.6 µs 842.5 µs +6.65%
small 11.5 µs 11.1 µs +3.34%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing refactor/fallback-alias (807393e) with main (4837a2e)

Open in CodSpeed

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Boshen
Boshen merged commit d69fc38 into main Jul 2, 2026
18 checks passed
@Boshen
Boshen deleted the refactor/fallback-alias branch July 2, 2026 07:30
@oxc-guard oxc-guard Bot mentioned this pull request Jul 2, 2026
Boshen added a commit that referenced this pull request Jul 2, 2026
Two cross-file dedups plus stale-allow removal:

- **`push_normalized_component`** existed twice — `path.rs` and
`cache/cached_path.rs` — identical except the cached-path copy trims the
trailing `\0` that uvwasi appends to directory entries on wasm
([nodejs/uvwasi#262](nodejs/uvwasi#262)). This
keeps one `pub` wasm-aware version in `path.rs`. Note this means
`path.rs` callers (tsconfig path joins) now also get the `\0`-trim on
wasm; on native targets the generated code is unchanged, and the helper
stays `#[inline]` so the hot `normalize_with` path keeps its codegen.
- **`manual_tsconfig()`**: the "manually configured tsconfig,
deliberately skipping `Auto` discovery" match block was duplicated
verbatim in `lib.rs` (`resolve`) and `dts_resolver.rs`
(`dts_resolve_tsconfig_paths`). One helper in `tsconfig_resolver.rs` now
owns it, and `find_tsconfig_manual` drops its `pub(crate)`.
- **Stale allows**: `clippy::cognitive_complexity` on `extend_tsconfig`
and `clippy::too_many_lines` on `dts_try_extensions`' neighbor no longer
suppress anything (verified by removing them and running the CI clippy
command); `extend_tsconfig` keeps `too_many_lines` (139/100).

Part of a second cleanup pass; follows #1264#1268.
Boshen added a commit that referenced this pull request Jul 2, 2026
…#1270)

The two "resolve from symlinks" benches did, per timed iteration, 10,000
eager `format!("./file{i}")` allocations plus an `assert!(.. .is_ok())`
branch — unlike every sibling bench in the file, which iterates
precomputed data and discards results with `_ =`. The asserts also
re-checked an invariant already validated once before the benchmark
group runs.

This precomputes the specifiers once (mirroring the `find tsconfig`
bench's hoisting pattern) and drops the in-loop asserts, so the benches
measure symlink resolution rather than resolution + allocation noise.
The validation pass also now constructs one resolver instead of 10,000.

**Heads-up:** this will step-change the CodSpeed series for
`resolver_memory/resolve from symlinks` and `resolver_real/resolve from
symlinks` downward — that's the removed allocation/assert overhead, not
a resolver perf change.

Part of a second cleanup pass; follows #1264#1268.
Boshen added a commit that referenced this pull request Jul 2, 2026
Small leftovers found while sweeping the test suite and the JS side:

- `src/tests/resolve.rs`: the "file in module with query and fragment"
table row appeared twice, byte-identical — the upstream enhanced-resolve
`resolve.test.js` has the case exactly once, so the second row was a
copy-paste in the port. The loop just ran the same assertion twice.
- `src/tests/alias.rs`: `#[allow(clippy::too_many_lines)]` no longer
suppresses anything (verified by removing it and running the CI clippy
command). The same allow in `imports_field.rs` is still load-bearing
(1191/100) and stays.
- `vite.config.ts`: `"napi/browser.js"` was listed twice in
`fmt.ignorePatterns`.
- `napi/test.mjs`: removed a stale comment about a `.ts` extension next
to code that adds `.mjs` and resolves an already-suffixed specifier.
- `napi/webcontainer-fallback.js`: removed an inert lint directive (`//
eslint-disable-next-line: no-console`) — the project lints with oxlint,
the syntax is invalid even for ESLint, and `no-console` isn't enabled.

Part of a second cleanup pass; follows #1264#1268.
Boshen pushed a commit that referenced this pull request Jul 2, 2026
## 🤖 New release

* `oxc_resolver`: 11.22.0 -> 11.23.0
* `oxc_resolver_napi`: 11.22.0 -> 11.23.0

<details><summary><i><b>Changelog</b></i></summary><p>

## `oxc_resolver`

<blockquote>

##
[11.23.0](v11.22.0...v11.23.0)
- 2026-07-02

### <!-- 0 -->🚀 Features

- *(tsconfig)* expose outDir, declarationDir, resolveJsonModule, checkJs
([#1257](#1257)) (by
@Boshen)

### <!-- 1 -->🐛 Bug Fixes

- *(exports)* propagate the last error in array target resolution
([#1267](#1267)) (by
@Boshen)

### <!-- 2 -->🚜 Refactor

- deduplicate cross-file helpers, drop stale lint allows
([#1269](#1269)) (by
@Boshen)
- *(dts)* deduplicate package entry selection and remove dead code
([#1266](#1266)) (by
@Boshen)
- *(tsconfig)* skip TsConfig deep clone for non-root configs
([#1265](#1265)) (by
@Boshen)
- *(alias)* compile fallback aliases once at construction
([#1264](#1264)) (by
@Boshen)

### <!-- 4 -->⚡ Performance

- *(alias)* scan a packed first-byte array instead of striding over
alias entries
([#1260](#1260)) (by
@Boshen)

### Contributors

* @Boshen
</blockquote>



</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: oxc-guard[bot] <276638029+oxc-guard[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant