Skip to content

Commit 4bb9b12

Browse files
committed
review
1 parent ff89b09 commit 4bb9b12

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/blog/tanstack-router-route-matching-tree-rewrite.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ The reason we can get such a massive performance boost is because we've changed
2424
- Old approach: `O(N)` where `N` is the number of routes in the tree.
2525
- New approach: `O(M)` where `M` is the number of segments in the pathname.
2626

27+
(This is very simplified, it's probably more something like `O(N * M)` vs. `O(M * log(N))`, but the point stands: we're scaling differently now.)
28+
2729
Using this new trie structure, each check eliminates a large number of possible routes, allowing us to quickly zero in on the correct match.
2830

2931
Say for example we have a route tree with 450 routes (pretty big app) and the tree can only eliminate 50% of routes at each segment check (this is unusually bad, it's often much higher). In 9 checks we have found a match (`2**9 > 450`). By contrast, the old approach *could* have found the match on the first check, but in the worst case it would have had to check all 450 routes, which yields an average of 225 checks. Even in this bad, simplified, and very unusual case, we are looking at a 25× performance improvement.
@@ -98,7 +100,7 @@ And to read from the bitmask:
98100
if (skipped & (1 << depth)) // segment at 'depth' was skipped
99101
```
100102

101-
The downside is that this limits us to 32 segments, beyond which optional segments will never be considered skipped. We could extend this to a `BigInt` if needed, but for now, it's feels reasonable.
103+
The downside is that this limits us to 32 segments. After the 32nd segment, optional segments can never be skipped. We could extend this to a `BigInt` if needed, but for now, it's feels reasonable.
102104

103105

104106
### Reusing Typed Arrays for Segment Parsing

0 commit comments

Comments
 (0)