next.js
4f523905 - [Segment Cache] Prioritize route trees over segments (#75213)

Commit
346 days ago
[Segment Cache] Prioritize route trees over segments (#75213) When processing the prefetch queue, we should prioritize fetching the route trees for all the links before we fetch any of the segments. The reason the route tree is more important is because it tells us the structure of the target page; from this alone, we can determine which segments are already cached and skip them during the navigation. Whereas if the route tree is missing at the time of the navigation, we cannot instruct the server to skip over prefetched segments, because we don't know which ones to skip. To implement this, I added a `phase` property to the PrefetchTask type. This is essentially a secondary priority field that changes as the task progresses. There are two phases: `RouteTree` and `Segments`. Any task in the `RouteTree` phase has higher priority than tasks in the `Segments` phase. Another way to implement this would be to add a secondary queue for segment prefetches. This would require reference counting to clean up segments when there are no more tasks that depend on them. The ref count could also be used as an additional prioritization heuristic: shared layouts with many dependent tasks could be prioritized over segments with fewer. However, I'm not sure the benefits are worth the extra code/complexity, so I'm starting with this simpler approach.
Author
Parents
Loading