Repository navigation
Commit 8f95264
authored
perf(pages): overlap route component imports with data requests (#654)
## Issue
Unprefetched Pages navigations currently wait for page data before
importing the destination component and layouts. If both data fetching
and component fetching takes long, the waterfall effect is significant.
## Fix
Start imports for known same-origin GET destinations alongside the data
request, then reuse them only when the response selects the matched
page.
Redirects and rewrites still render the server-selected component.
Unknown routes, islands, mutations, and other-origin visits do not
speculate; unused or aborted import failures do not break a later
navigation.
> [!CAUTION]
>
> 1. In the uncommon case of redirects, the component is prefetched and
unused, leading to redundant work. I think this tradeoff is alright
though.
>
> 2. This uses dynamic `import()`, so module-level code and transitive
dependencies can execute, and route CSS can apply, before the data
response or server middleware decision arrives. The router waits for the
response before rendering the destination. A redirect or cancellation
cannot undo import side effects. Existing explicit component prefetching
has the same caveat; this change extends that timing to ordinary GET
navigation.
Benchmarks use the real React Pages client in Chrome, with 12 adjacent
baseline/candidate pairs per scenario. Cold cases use simulated response
delays on localhost; these are scheduling measurements, not production
latency claims.
| Scenario | Before | After | Mean latency reduction |
| --- | ---: | ---: | ---: |
| Cold, no added delay | 4.02 ms | 3.84 ms | 4.4% |
| Cold, 80 ms data / 80 ms assets | 169.56 ms | 85.18 ms | 49.8% |
| Cold, 160 ms data / 40 ms assets | 210.79 ms | 165.92 ms | 21.3% |
| Cold, 40 ms data / 160 ms assets | 209.92 ms | 166.47 ms | 20.7% |
| Warm modules, 80 ms data | 84.77 ms | 84.30 ms | 0.6% |
| Completed data and component prefetch | 2.30 ms | 2.22 ms | 3.3% |
Either way, it's an improvement!
## Validation:
- `vp run test:all`: formatting, lint, package/platform/playground
builds, artifact checks, typechecks, and the full suite passed (759
files, 15,370 tests; 31 tests skipped).
- The final identifier/comment cleanup passed the 91-test router suite,
lint, and all 33 `vp run check` tasks.
- Regression coverage includes import/data overlap, waiting for layouts,
rewrites, redirects, import failures, aborted visits, and excluded
destinations.
- Benchmark repository checks and three-page SSR/SSG/runtime smoke
comparisons passed, including hydration, navigation, and HMR. Both
canonical workloads were restored to 10,000 pages.1 parent c242d7b commit 8f95264
2 files changed
Lines changed: 194 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
643 | 654 | | |
644 | 655 | | |
645 | 656 | | |
| |||
829 | 840 | | |
830 | 841 | | |
831 | 842 | | |
| 843 | + | |
| 844 | + | |
832 | 845 | | |
833 | | - | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
834 | 849 | | |
835 | 850 | | |
836 | 851 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
79 | 89 | | |
80 | 90 | | |
81 | 91 | | |
| |||
138 | 148 | | |
139 | 149 | | |
140 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
141 | 319 | | |
142 | 320 | | |
143 | 321 | | |
| |||
0 commit comments