Skip to content

perf(url): avoid full parse when reading hash on the fast path - #296

Open
danielroe wants to merge 1 commit into
h3js:mainfrom
danielroe:perf/fast-url-hash
Open

perf(url): avoid full parse when reading hash on the fast path#296
danielroe wants to merge 1 commit into
h3js:mainfrom
danielroe:perf/fast-url-hash

Conversation

@danielroe

@danielroe danielroe commented Aug 30, 2026

Copy link
Copy Markdown
Member

context: found this profiling Nuxt's SSR path, where we build the render URL as pathname + search + hash

reading url.hash on a FastURL costs a full parse, because there's no hash getter

but ... there's nothing to find in that parse on the fast path. so in that case we can optimise by returning ''. quick measurement: 500k iterations, node 22, object-form input:

hash (object form)               316 ns -> 40 ns
hash (origin-form string)        229 ns -> 25 ns
hash (absolute string with '#')  228 ns -> 228 ns
pathname (already fast)           40 ns

Summary by CodeRabbit

  • New Features

    • Added a hash property to URL handling, enabling access to URL fragments.
    • Fragment values are preserved for absolute URLs and reflected when updated.
  • Bug Fixes

    • Improved fragment parsing consistency across URL formats.
    • Ensured fragment values remain consistent before and after URL processing.

@danielroe
danielroe requested a review from pi0 as a code owner August 30, 2026 10:02
@vercel

vercel Bot commented Aug 30, 2026

Copy link
Copy Markdown

@danielroe is attempting to deploy a commit to the unjs Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 72c9e57f-c619-44f2-84f6-1210c0373361

📥 Commits

Reviewing files that changed from the base of the PR and between 053be62 and 176ffcb.

📒 Files selected for processing (2)
  • src/_url.ts
  • test/url.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

FastURL now exposes a hash getter. Fast-path URLs return an empty hash, while materialized URLs delegate to the native URL. Tests cover fragments, deoptimization, absolute-form inputs, and setter behavior.

Changes

FastURL hash support

Layer / File(s) Summary
Add FastURL hash access
src/_url.ts
The documentation lists url.hash as fast-path accessible. The getter returns an empty string on the fast path and delegates to the native URL after materialization.
Validate hash behavior
test/url.test.ts
Tests compare hashes with native URL parsing and cover fast-path, absolute-form, deoptimized, and setter behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 176ff

The change optimizes hash reads on the FastURL path while preserving native hash writes and request-target fragment exclusion; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: pi0, pi0x

Poem

A rabbit checked the fragment trail,
And found the hash where URLs sail.
Fast paths kept the string serene,
Native paths showed what lay unseen.
Tests hopped after, all was green.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: avoiding full URL parsing when reading hash on the fast path.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/srvx@296

commit: 176ffcb

@codecov

codecov Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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