Skip to content

perf: borrow relative main field instead of allocating a "./" prefix#1187

Merged
graphite-app[bot] merged 1 commit into
mainfrom
perf/main-field-borrow-skip-format
May 30, 2026
Merged

perf: borrow relative main field instead of allocating a "./" prefix#1187
graphite-app[bot] merged 1 commit into
mainfrom
perf/main-field-borrow-skip-format

Conversation

@Boshen

@Boshen Boshen commented May 30, 2026

Copy link
Copy Markdown
Member

load_as_directory prefixed every main field that didn't already start with ./ or ../ with format!("./{main_field}"), allocating a String for the common "main": "index.js" / "dist/index.js" shapes (the dominant CJS package-entry path).

CachedPath::normalize_with treats a leading ./ (Component::CurDir) as a no-op, so a bare relative field collapses to the identical CachedPath whether or not the ./ is present. This borrows the field directly and only builds the owned ./-prefixed form when it is actually required:

  • an empty field — must become ./ to resolve the directory itself, and
  • an absolute path — whose RootDir/Prefix head must stay behind the ./ so it is joined rather than replacing the package directory.

Resolution results are unchanged (the owned form is kept for exactly the cases where normalize_with would otherwise diverge).

🤖 Generated with Claude Code

@codecov

codecov Bot commented May 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.77%. Comparing base (aba01c3) to head (4e04a04).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1187   +/-   ##
=======================================
  Coverage   93.77%   93.77%           
=======================================
  Files          22       22           
  Lines        4210     4212    +2     
=======================================
+ Hits         3948     3950    +2     
  Misses        262      262           

☔ View full report in Codecov by Sentry.
📢 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 May 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚡ 4 improved benchmarks
❌ 3 regressed benchmarks
✅ 14 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 969.2 µs 1,017.6 µs -4.76%
pm/bun-isolated 1.1 ms 1.1 ms -4.92%
pm/yarn-flat 986 µs 913.9 µs +7.89%
pm/yarn-isolated 1.1 ms 1 ms +4.69%
resolver_real[multi-thread] 397.4 µs 384.4 µs +3.4%
pm/pnpm-hoisted 1.1 ms 1.1 ms +4.39%
pm/pnpm-isolated 1.1 ms 1.1 ms -4.26%

Tip

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


Comparing perf/main-field-borrow-skip-format (4e04a04) with main (aba01c3)2

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.

  2. No successful run was found on main (4e04a04) during the generation of this report, so aba01c3 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Boshen Boshen added the merge label May 30, 2026

Boshen commented May 30, 2026

Copy link
Copy Markdown
Member Author

Merge activity

…1187)

`load_as_directory` prefixed every `main` field that didn't already start with `./` or `../` with `format!("./{main_field}")`, allocating a `String` for the common `"main": "index.js"` / `"dist/index.js"` shapes (the dominant CJS package-entry path).

`CachedPath::normalize_with` treats a leading `./` (`Component::CurDir`) as a no-op, so a bare relative field collapses to the identical `CachedPath` whether or not the `./` is present. This borrows the field directly and only builds the owned `./`-prefixed form when it is actually required:

- an **empty** field — must become `./` to resolve the directory itself, and
- an **absolute** path — whose `RootDir`/`Prefix` head must stay behind the `./` so it is joined rather than replacing the package directory.

Resolution results are unchanged (the owned form is kept for exactly the cases where `normalize_with` would otherwise diverge).

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app Bot force-pushed the perf/main-field-borrow-skip-format branch from d53849d to 4e04a04 Compare May 30, 2026 03:47
@graphite-app graphite-app Bot merged commit 4e04a04 into main May 30, 2026
18 checks passed
@graphite-app graphite-app Bot removed the merge label May 30, 2026
@graphite-app graphite-app Bot deleted the perf/main-field-borrow-skip-format branch May 30, 2026 03:50
@oxc-guard oxc-guard Bot mentioned this pull request May 30, 2026
Boshen pushed a commit that referenced this pull request Jun 3, 2026
## 🤖 New release

* `oxc_resolver`: 11.20.0 -> 11.21.0
* `oxc_resolver_napi`: 11.20.0 -> 11.21.0

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

## `oxc_resolver`

<blockquote>

##
[11.21.0](v11.20.0...v11.21.0)
- 2026-06-03

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

- *(tsconfig)* support package.json imports field in extends
([#1199](#1199)) (by
@Boshen)

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

- *(tsconfig)* apply each referenced project's own `allowJs`
([#1198](#1198)) (by
@shulaoda)
- make symlink_metadata VPath-aware for Yarn PnP
([#1183](#1183)) (by
@Boshen)

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

- borrow relative main field instead of allocating a "./" prefix
([#1187](#1187)) (by
@Boshen)
- *(cache)* move package.json path into parse instead of cloning
([#1186](#1186)) (by
@Boshen)
- eliminate symlink stat syscalls by reusing canonicalization
([#1184](#1184)) (by
@Boshen)
- reduce resolution syscalls by unifying stat and lstat
([#1182](#1182)) (by
@Boshen)

### <!-- 9 -->💼 Other

- add baselines for each package manager x node_modules layout
([#1176](#1176)) (by
@Boshen)

### Contributors

* @shulaoda
* @Boshen
* @renovate[bot]
</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