Skip to content

refactor(router): refactor and simplify router RxJS chains - #40290

Closed
martinsik wants to merge 1 commit into
angular:masterfrom
martinsik:router-refactor-observables
Closed

martinsik wants to merge 1 commit into
angular:masterfrom
martinsik:router-refactor-observables

Conversation

@martinsik

@martinsik martinsik commented Jan 1, 2021 •

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

I refactored and simplified some RxJS usage in the Router package in order to reduce its size and increase performance. Unfortunatelly, I'm not able to verify the package size because node ./scripts/build/build-packages-dist.js fails on my system for some reason.

The biggest changes are these:

  • Some custom operators were wrapped with another function even though they didn't need source Observable.
  • from([x, y, z]) is the same as of(x, y, z) and using of() should be faster (I'll need to test this).

There are some other usecases that seem suspicious like using from().pipe(mergeAll()) should be the same as using just merge() but I'll need to be able to run build-packages-dist.js to make sure it generates smaller package.

Bundle size main-es2015 in cli-hello-world-lazy-rollup integration test dropped from expected 218507 to 217931.
Bundle size main-es2015 in cli-hello-world-lazy integration test dropped from expected 241837 to 241260.
So both bundles are cca 580 B smaller.

I'm not sure about the removed records in bundle.golden_symbols.json. It has probably something to do with this change https://github.com/angular/angular/pull/40290/files#diff-1706bbbdd4dda445171e80023d67b54f1aa77a457d6b81b6815239113fd34decR62-R66 but I'm not sure why.

I didn't make any change to existing tests because this should not break anything.

@pullapprove
pullapprove Bot requested a review from atscott January 1, 2021 11:05
@ngbot ngbot Bot added this to the Backlog milestone Jan 1, 2021
@google-cla

google-cla Bot commented Jan 1, 2021

Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@google-cla google-cla Bot added the cla: no label Jan 1, 2021
@martinsik
martinsik force-pushed the router-refactor-observables branch from 284127d to 7cdc344 Compare January 1, 2021 11:15
@google-cla google-cla Bot added cla: yes and removed cla: no labels Jan 1, 2021
@martinsik
martinsik force-pushed the router-refactor-observables branch from 7cdc344 to be037b0 Compare January 1, 2021 11:48
@pullapprove pullapprove Bot added the area: core Issues related to the framework runtime label Jan 1, 2021
@martinsik
martinsik force-pushed the router-refactor-observables branch 2 times, most recently from 1bbb7af to 861a400 Compare January 1, 2021 12:40

@atscott atscott left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing these wrapper functions was a great change. Thanks!

Comment thread packages/router/src/operators/check_guards.ts Outdated
Comment thread packages/router/src/router.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the removal of the taps. The Router rxjs chain is hard enough to follow without extra operators thrown in there.

@pullapprove pullapprove Bot added the area: build & ci Related the build and CI infrastructure of the project label Jan 4, 2021
@atscott atscott added action: presubmit The PR is in need of a google3 presubmit target: patch This PR is targeted for the next patch release and removed area: build & ci Related the build and CI infrastructure of the project labels Jan 4, 2021
@pullapprove pullapprove Bot added area: build & ci Related the build and CI infrastructure of the project and removed action: presubmit The PR is in need of a google3 presubmit target: patch This PR is targeted for the next patch release labels Jan 4, 2021
@atscott atscott added the target: patch This PR is targeted for the next patch release label Jan 4, 2021

@atscott atscott left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed-for: size-tracking

@pullapprove
pullapprove Bot requested a review from IgorMinar January 4, 2021 17:42
@atscott atscott added action: presubmit The PR is in need of a google3 presubmit state: blocked labels Jan 4, 2021
@atscott

atscott commented Jan 4, 2021

Copy link
Copy Markdown
Contributor

Adding blocked label, as #40029 has been waiting to go in and should be submitted first. That PR will cause merge conflicts with a couple changes here.

@martinsik
martinsik force-pushed the router-refactor-observables branch from 861a400 to bea520a Compare January 4, 2021 22:47
@martinsik

martinsik commented Jan 4, 2021 •

Copy link
Copy Markdown
Contributor Author

I reverted take(1) back to first(). I know it wouldn't have any impact on package size but it would be more efficient. However, I forgot that first() will emit an error if the source Observable completes without emitting any value while take(1) won't. I answered the exact same question a while ago on StackOverflow and then completely forgot about it :).
All tests passed but it didn't occur to me that this use-case might not be tested and it really looks like it isn't (unless I missed it when looking into router.spec.ts).

I reverted also takeLast(1) with last() because that's the same issue.

@martinsik
martinsik force-pushed the router-refactor-observables branch from bea520a to 351c610 Compare January 4, 2021 23:17
@atscott

atscott commented Jan 4, 2021

Copy link
Copy Markdown
Contributor

I reverted take(1) back to first(). I know it wouldn't have any impact on package size but it would be more efficient. However, I forgot that first() will emit an error if the source Observable completes without emitting any value while take(1) won't. I answered the exact same question a while ago on StackOverflow and then completely forgot about it :).
All tests passed but it didn't occur to me that this use-case might not be tested and it really looks like it isn't (unless I missed it when looking into router.spec.ts).

I reverted also takeLast(1) with last() because that's the same issue.

@martinsik - I do like the idea of the change and appreciate you bringing it up! I just want to be a little careful about it since we know that changes to the router often cause unexpected failures. How about creating a separate PR for those changes (first() => take(1) and last() => takeLast(1))?

@martinsik
martinsik force-pushed the router-refactor-observables branch from 351c610 to 4ce60f7 Compare January 5, 2021 09:25
@pullapprove pullapprove Bot removed the area: build & ci Related the build and CI infrastructure of the project label Jan 5, 2021
@martinsik
martinsik force-pushed the router-refactor-observables branch from 4ce60f7 to 4bbd6c9 Compare January 5, 2021 09:44
@pullapprove pullapprove Bot added the area: build & ci Related the build and CI infrastructure of the project label Jan 5, 2021

@petebacondarwin petebacondarwin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: size-tracking

@martinsik

martinsik commented Jan 5, 2021 •

Copy link
Copy Markdown
Contributor Author

@atscott I'll try doing that in a separate PR. I think I'll need to write tests cases where the guards don't emit (eg. return EMPTY) because I'm very suspicious that using take(1) will have different behavior than first(). So maybe it won't be even possible to use take(1) instead. Of course, unless the error from first() is caught somewhere down the chain.

@IgorMinar IgorMinar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice cleanup! thank you

Reviewed-for: size-tracking

@atscott

atscott commented Jan 8, 2021

Copy link
Copy Markdown
Contributor

Hi @martinsik, could you rebase this PR. I'd like to merge it early next week (or today if you're around to do the rebase).

@atscott atscott added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jan 8, 2021

@jelbourn jelbourn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Reviewed-for: size-tracking

@martinsik
martinsik force-pushed the router-refactor-observables branch from 4bbd6c9 to 115f06f Compare January 10, 2021 19:28
Refactor and simplifiy RxJS usage in the router package
in order to reduce its size and increase performance.
@martinsik
martinsik force-pushed the router-refactor-observables branch from 115f06f to c7dd878 Compare January 10, 2021 19:45
@martinsik

Copy link
Copy Markdown
Contributor Author

@atscott Rebased. However, I wasn't able to check package sizes because I can't run node ./scripts/build/build-packages-dist.js locally and the ci/angular: size task is not failing with the values in master :).

@atscott atscott added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews action: presubmit The PR is in need of a google3 presubmit labels Jan 11, 2021
@atscott
atscott removed the request for review from alxhub January 11, 2021 22:09
atscott pushed a commit that referenced this pull request Jan 11, 2021
Refactor and simplifiy RxJS usage in the router package
in order to reduce its size and increase performance.

PR Close #40290
@atscott atscott closed this in 9105005 Jan 11, 2021
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Feb 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: build & ci Related the build and CI infrastructure of the project area: core Issues related to the framework runtime area: router cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note risk: medium target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants