Repository navigation
Commit 14793bf
committed
perf(router): do not retain UrlTree instances in RouterLink
In 89d47d8, RouterLink internals were
refactored to use signals, introducing a computed signal `_urlTree`.
Because every `<a routerLink>` maintains an active RouterLink directive
instance for the lifetime of the view/request, the computed signal
permanently cached the returned UrlTree (and its cloned queryParams map
and segment tree) in `ReactiveNode.value` for every link.
During server-side rendering (SSR), especially when query parameters are
large or when `defaultQueryParamsHandling: 'merge'` is enabled, each
rendered link held a full copy of the query parameter map pinned in the
heap. In an application with 100 links and thousands of query parameters,
this pinned over 50 MB of heap per in-flight request, causing server
workers to crash with Out of Memory (OOM) under concurrent load (#70908).
This change moves the reactive dependencies (`path`, `fragment`, and
`queryParams`) directly into `reactiveHref` so it computes and retains
only the serialized href string. The intermediate UrlTree and its
queryParams dictionary are discarded immediately after serialization and
collected during young-generation GC scavenges rather than remaining
pinned in the heap. The public `urlTree` getter and `onClick` handler now
compute the tree on demand, restoring the memory profile prior to
89d47d8.
Fixes #70908
(cherry picked from commit 319a3c4)1 parent b9a8605 commit 14793bf
1 file changed
Lines changed: 40 additions & 47 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
199 | 212 | | |
200 | 213 | | |
201 | 214 | | |
| |||
388 | 401 | | |
389 | 402 | | |
390 | 403 | | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
391 | 408 | | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
| 409 | + | |
| 410 | + | |
400 | 411 | | |
401 | 412 | | |
402 | 413 | | |
| |||
483 | 494 | | |
484 | 495 | | |
485 | 496 | | |
486 | | - | |
| 497 | + | |
487 | 498 | | |
488 | 499 | | |
489 | 500 | | |
| |||
534 | 545 | | |
535 | 546 | | |
536 | 547 | | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
573 | 566 | | |
574 | 567 | | |
575 | | - | |
| 568 | + | |
576 | 569 | | |
577 | 570 | | |
578 | 571 | | |
| |||
0 commit comments