perf(build): optimize buildAppStaticPaths performance and add helper function (#81386)
### What?
Optimizes the `buildAppStaticPaths` function performance and extracts a
helper function `calculateFallbackMode` to reduce code duplication.
### Why?
The `buildAppStaticPaths` function had several performance bottlenecks:
1. **Repeated regex pattern compilation**: Route parameter patterns were
being compiled inside the loop for every route, causing unnecessary
overhead
2. **Inefficient root parameter lookups**: Using `Array.includes()` for
root parameter checks resulted in O(n) lookups for each parameter
3. **Duplicated fallback mode logic**: The same fallback mode
calculation was repeated in multiple places, making the code harder to
maintain and prone to inconsistencies
These inefficiencies became more apparent when processing large numbers
of routes with complex parameter structures.
### How?
**Performance optimizations:**
- Pre-compile regex patterns for route parameters outside the loop and
store them in a Map for O(1) lookups
- Convert `rootParamKeys` to a Set for O(1) lookup time instead of O(n)
array searches
- Optimize the fallback parameter collection loop to break early and
avoid redundant iterations
**Code organization:**
- Extract `calculateFallbackMode` helper function to eliminate code
duplication
- Add comprehensive tests for the new helper function to ensure
correctness
- Simplify the main loop logic by using the pre-compiled patterns and
optimized data structures