[PR #718] [MERGED] perf: optimize resolveParentParams lookups #796

Closed
opened 2026-05-06 13:10:09 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/718
Author: @NathanDrake2406
Created: 3/30/2026
Status: Merged
Merged: 3/30/2026
Merged by: @james-elicx

Base: mainHead: perf/resolve-parent-params


📝 Commits (5)

  • 3531955 test: add direct unit tests for resolveParentParams
  • 4210d7c perf: optimize resolveParentParams lookups
  • b0c62a3 test: add edge case tests for resolveParentParams
  • 4e307c1 refactor: simplify resolveParentParams internals
  • 73a246f refactor: address bonk review nits in resolveParentParams

📊 Changes

2 files changed (+182 additions, -41 deletions)

View changed files

📝 packages/vinext/src/build/prerender.ts (+40 -40)
📝 tests/prerender.test.ts (+142 -1)

📄 Description

Summary

  • Map-based route index for O(1) parent route lookups (was O(N) linear scan via allRoutes.find())
  • Reuse pre-computed patternParts from AppRoute instead of re-splitting the pattern string on every call
  • Pre-compute last dynamic segment index via single reverse scan (was per-iteration slice().some() allocation)
  • Incremental prefix string building instead of slice(0, i+1).join("/") per dynamic segment
  • Remove dead ParentSegment.params field (allocated but never read)
  • Export StaticParamsMap type for reuse across production code and tests

These are in-memory micro-optimizations (~1ms savings on a 500-route site). The expensive HTTP fetches are already deduplicated by staticParamsCache. The wins are small but the code is cleaner — fewer allocations, O(1) lookups, and no dead fields.

Partially addresses #563 (ticks the resolveParentParams lookups checkbox).

Test plan

  • 9 direct unit tests for resolveParentParams covering: no parents, missing pagePath, missing generateStaticParams, single parent, two-level nesting, static segments between dynamic parents, fully static routes, single-segment dynamic routes, catch-all child segments
  • Full tests/prerender.test.ts integration suite passes (including nested /shop/[category]/[item] top-down params)
  • CI: Check, Vitest, Playwright E2E

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/718 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/30/2026 **Status:** ✅ Merged **Merged:** 3/30/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `perf/resolve-parent-params` --- ### 📝 Commits (5) - [`3531955`](https://github.com/cloudflare/vinext/commit/353195530e9399435e96203587685c49d468b946) test: add direct unit tests for resolveParentParams - [`4210d7c`](https://github.com/cloudflare/vinext/commit/4210d7c12bb626fb843b037079d5578ed5582693) perf: optimize resolveParentParams lookups - [`b0c62a3`](https://github.com/cloudflare/vinext/commit/b0c62a376a6aa875acc87ba213012fb91805a24d) test: add edge case tests for resolveParentParams - [`4e307c1`](https://github.com/cloudflare/vinext/commit/4e307c1481c6706a47ec0038d3acd9d91adf643f) refactor: simplify resolveParentParams internals - [`73a246f`](https://github.com/cloudflare/vinext/commit/73a246f18b38bd35d670c4479e09579c857045af) refactor: address bonk review nits in resolveParentParams ### 📊 Changes **2 files changed** (+182 additions, -41 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/build/prerender.ts` (+40 -40) 📝 `tests/prerender.test.ts` (+142 -1) </details> ### 📄 Description ## Summary - **Map-based route index** for O(1) parent route lookups (was O(N) linear scan via `allRoutes.find()`) - **Reuse pre-computed `patternParts`** from `AppRoute` instead of re-splitting the pattern string on every call - **Pre-compute last dynamic segment index** via single reverse scan (was per-iteration `slice().some()` allocation) - **Incremental prefix string building** instead of `slice(0, i+1).join("/")` per dynamic segment - **Remove dead `ParentSegment.params` field** (allocated but never read) - **Export `StaticParamsMap` type** for reuse across production code and tests These are in-memory micro-optimizations (~1ms savings on a 500-route site). The expensive HTTP fetches are already deduplicated by `staticParamsCache`. The wins are small but the code is cleaner — fewer allocations, O(1) lookups, and no dead fields. Partially addresses #563 (ticks the `resolveParentParams` lookups checkbox). ## Test plan - [x] 9 direct unit tests for `resolveParentParams` covering: no parents, missing pagePath, missing generateStaticParams, single parent, two-level nesting, static segments between dynamic parents, fully static routes, single-segment dynamic routes, catch-all child segments - [x] Full `tests/prerender.test.ts` integration suite passes (including nested `/shop/[category]/[item]` top-down params) - [ ] CI: Check, Vitest, Playwright E2E --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:10:09 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#796
No description provided.