Commit 84b5451
refactor(router-core): reduce buildLocation object allocations (#4981)
When we can (and it's reasonable), it's always beneficial to reduce the
number of objects we create in JS, so as to minimize the memory pressure
and the GC work.
`buildLocation` gets called pretty often, so removing a few object
allocations can be very beneficial (especially inside loops).
Also, from a purely "immediate performance" point of view,
`Object.assign` tends to be faster than `{...foo}`.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Refactor**
* Route parameter and search handling now use in-place updates to reduce
allocations and streamline iteration/control flow; behavior and public
API remain unchanged.
* **Tests**
* Updated tests to capture cloned parameter objects and assert on exact
values rather than relying on mock call history, preventing
mutation-related flakiness.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>1 parent dfa089e commit 84b5451
3 files changed
Lines changed: 48 additions & 51 deletions
File tree
- packages
- react-router/tests
- router-core/src
- solid-router/tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4024 | 4024 | | |
4025 | 4025 | | |
4026 | 4026 | | |
4027 | | - | |
4028 | | - | |
| 4027 | + | |
| 4028 | + | |
4029 | 4029 | | |
4030 | 4030 | | |
4031 | 4031 | | |
| |||
4036 | 4036 | | |
4037 | 4037 | | |
4038 | 4038 | | |
4039 | | - | |
| 4039 | + | |
4040 | 4040 | | |
4041 | 4041 | | |
4042 | 4042 | | |
4043 | 4043 | | |
4044 | 4044 | | |
4045 | 4045 | | |
4046 | | - | |
| 4046 | + | |
4047 | 4047 | | |
4048 | 4048 | | |
4049 | 4049 | | |
| |||
4061 | 4061 | | |
4062 | 4062 | | |
4063 | 4063 | | |
4064 | | - | |
| 4064 | + | |
4065 | 4065 | | |
4066 | 4066 | | |
4067 | 4067 | | |
| |||
4070 | 4070 | | |
4071 | 4071 | | |
4072 | 4072 | | |
4073 | | - | |
| 4073 | + | |
4074 | 4074 | | |
4075 | 4075 | | |
4076 | 4076 | | |
| |||
4086 | 4086 | | |
4087 | 4087 | | |
4088 | 4088 | | |
4089 | | - | |
4090 | | - | |
| 4089 | + | |
| 4090 | + | |
4091 | 4091 | | |
4092 | 4092 | | |
4093 | 4093 | | |
| |||
4099 | 4099 | | |
4100 | 4100 | | |
4101 | 4101 | | |
4102 | | - | |
| 4102 | + | |
4103 | 4103 | | |
4104 | 4104 | | |
4105 | 4105 | | |
4106 | 4106 | | |
4107 | 4107 | | |
4108 | 4108 | | |
4109 | | - | |
| 4109 | + | |
4110 | 4110 | | |
4111 | 4111 | | |
4112 | 4112 | | |
| |||
4125 | 4125 | | |
4126 | 4126 | | |
4127 | 4127 | | |
4128 | | - | |
| 4128 | + | |
4129 | 4129 | | |
4130 | 4130 | | |
4131 | 4131 | | |
| |||
4134 | 4134 | | |
4135 | 4135 | | |
4136 | 4136 | | |
4137 | | - | |
| 4137 | + | |
4138 | 4138 | | |
4139 | 4139 | | |
4140 | 4140 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1480 | 1480 | | |
1481 | 1481 | | |
1482 | 1482 | | |
1483 | | - | |
| 1483 | + | |
1484 | 1484 | | |
1485 | 1485 | | |
1486 | 1486 | | |
1487 | 1487 | | |
1488 | | - | |
1489 | | - | |
1490 | | - | |
1491 | | - | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
1492 | 1492 | | |
1493 | 1493 | | |
1494 | 1494 | | |
1495 | 1495 | | |
1496 | | - | |
| 1496 | + | |
1497 | 1497 | | |
1498 | 1498 | | |
1499 | 1499 | | |
| |||
1503 | 1503 | | |
1504 | 1504 | | |
1505 | 1505 | | |
1506 | | - | |
1507 | | - | |
1508 | | - | |
1509 | | - | |
1510 | | - | |
1511 | | - | |
1512 | | - | |
1513 | | - | |
1514 | | - | |
1515 | | - | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
1516 | 1513 | | |
1517 | 1514 | | |
1518 | 1515 | | |
1519 | 1516 | | |
1520 | 1517 | | |
1521 | 1518 | | |
1522 | | - | |
| 1519 | + | |
1523 | 1520 | | |
1524 | 1521 | | |
1525 | 1522 | | |
| |||
1529 | 1526 | | |
1530 | 1527 | | |
1531 | 1528 | | |
1532 | | - | |
| 1529 | + | |
1533 | 1530 | | |
1534 | | - | |
1535 | | - | |
1536 | | - | |
1537 | | - | |
1538 | | - | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
1539 | 1536 | | |
1540 | 1537 | | |
1541 | | - | |
1542 | | - | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
1543 | 1542 | | |
1544 | | - | |
1545 | | - | |
1546 | 1543 | | |
1547 | 1544 | | |
1548 | 1545 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3592 | 3592 | | |
3593 | 3593 | | |
3594 | 3594 | | |
3595 | | - | |
3596 | | - | |
| 3595 | + | |
| 3596 | + | |
3597 | 3597 | | |
3598 | 3598 | | |
3599 | 3599 | | |
| |||
3604 | 3604 | | |
3605 | 3605 | | |
3606 | 3606 | | |
3607 | | - | |
| 3607 | + | |
3608 | 3608 | | |
3609 | 3609 | | |
3610 | 3610 | | |
3611 | 3611 | | |
3612 | 3612 | | |
3613 | 3613 | | |
3614 | | - | |
| 3614 | + | |
3615 | 3615 | | |
3616 | 3616 | | |
3617 | 3617 | | |
| |||
3629 | 3629 | | |
3630 | 3630 | | |
3631 | 3631 | | |
3632 | | - | |
| 3632 | + | |
3633 | 3633 | | |
3634 | 3634 | | |
3635 | 3635 | | |
| |||
3638 | 3638 | | |
3639 | 3639 | | |
3640 | 3640 | | |
3641 | | - | |
| 3641 | + | |
3642 | 3642 | | |
3643 | 3643 | | |
3644 | 3644 | | |
| |||
3654 | 3654 | | |
3655 | 3655 | | |
3656 | 3656 | | |
3657 | | - | |
3658 | | - | |
| 3657 | + | |
| 3658 | + | |
3659 | 3659 | | |
3660 | 3660 | | |
3661 | 3661 | | |
| |||
3667 | 3667 | | |
3668 | 3668 | | |
3669 | 3669 | | |
3670 | | - | |
| 3670 | + | |
3671 | 3671 | | |
3672 | 3672 | | |
3673 | 3673 | | |
3674 | 3674 | | |
3675 | 3675 | | |
3676 | 3676 | | |
3677 | | - | |
| 3677 | + | |
3678 | 3678 | | |
3679 | 3679 | | |
3680 | 3680 | | |
| |||
3693 | 3693 | | |
3694 | 3694 | | |
3695 | 3695 | | |
3696 | | - | |
| 3696 | + | |
3697 | 3697 | | |
3698 | 3698 | | |
3699 | 3699 | | |
| |||
3702 | 3702 | | |
3703 | 3703 | | |
3704 | 3704 | | |
3705 | | - | |
| 3705 | + | |
3706 | 3706 | | |
3707 | 3707 | | |
3708 | 3708 | | |
| |||
0 commit comments