Skip to content

refactor(router-core): decodePath fast path when no encoded chars - #6504

Merged
Sheraff merged 2 commits into
mainfrom
refactor-router-core-decode-path-fast-path
Jan 25, 2026
Merged

refactor(router-core): decodePath fast path when no encoded chars#6504
Sheraff merged 2 commits into
mainfrom
refactor-router-core-decode-path-fast-path

Conversation

@Sheraff

@SheraffSheraff commented Jan 25, 2026

Copy link
Copy Markdown
Collaborator

Most paths do not contain encoded paths and are just alphanumeric and -_/. We can optimize decodePath to return early in that case.

In our simple benchmark, this is a 3x improvement on the total time of decodePath from 156ms to 47ms (in a 30s run)

before
Screenshot 2026-01-25 at 11 39 05

after
Screenshot 2026-01-25 at 11 38 56

Summary by CodeRabbit

  • Chores
    • Optimized path decoding performance by adding an early-exit mechanism for already-decoded and safe paths, reducing unnecessary processing overhead.

✏️ Tip: You can customize this high-level summary in your review settings.

@nx-cloud

nx-cloudBot commented Jan 25, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit e30a1fb

CommandStatusDurationResult
nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded9m 54sView ↗
nx run-many --target=build --exclude=examples/*...✅ Succeeded1m 43sView ↗

☁️ Nx Cloud last updated this comment at 2026-01-25 10:56:53 UTC

@coderabbitai

coderabbitaiBot commented Jan 25, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds an early-exit fast path optimization to decodePath that immediately returns when input contains no encoded markers, backslashes, control characters, or protocol-relative patterns, bypassing the full decoding logic for already-safe paths.

Changes

Cohort / File(s)Summary
decodePath Fast Path Optimization
packages/router-core/src/utils.ts
Adds conditional check to skip decoding for paths that are already safe (no encoded characters, backslashes, control chars, or protocol-relative patterns); returns early before existing decode logic executes

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

performance

Suggested reviewers

  • schiller-manuel
  • nlynzaad

Poem

🐰 Hop-skip optimization so neat,
Fast paths make decodePath fleet,
Safe strings bypass decode's dance,
Quick return—no redundant prance!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title clearly and accurately describes the main change: adding a fast path optimization to the decodePath function that skips decoding when no encoded characters are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

@pkg-pr-new

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@6504

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@6504

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6504

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@6504

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@6504

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@6504

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@6504

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6504

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6504

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6504

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@6504

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@6504

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@6504

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@6504

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@6504

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@6504

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@6504

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@6504

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@6504

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@6504

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@6504

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@6504

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6504

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6504

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6504

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6504

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-fn-stubs@6504

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6504

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6504

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@6504

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6504

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6504

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6504

@tanstack/vue-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router@6504

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-devtools@6504

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-ssr-query@6504

@tanstack/vue-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@6504

@tanstack/vue-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-client@6504

@tanstack/vue-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-server@6504

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6504

commit: e30a1fb

@Sheraff
Sheraff merged commit 036b3b1 into mainJan 25, 2026
6 checks passed
@Sheraff
Sheraff deleted the refactor-router-core-decode-path-fast-path branch January 25, 2026 11:04
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@Sheraff