Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(SafeSubscriber): optimize perf for ordinary observers #6815

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor(Subscriber): reduce property access
  • Loading branch information
benlesh committed Feb 9, 2022
commit d2bbc4c468bc189d51291d5a48ca9422385f8f3e
15 changes: 9 additions & 6 deletions src/internal/Subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,21 @@ class ConsumerObserver<T> implements Observer<T> {
constructor(private partialObserver: Partial<Observer<T>>) {}

next(value: T): void {
if (this.partialObserver.next) {
const { partialObserver } = this;
if (partialObserver.next) {
try {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could access the partialObserver via this only once here: const { partialObserver } = this or whatever. There's no need to access it twice. Same for the other methods.

this.partialObserver.next(value);
partialObserver.next(value);
} catch (error) {
handleUnhandledError(error);
}
}
}

error(err: any): void {
if (this.partialObserver.error) {
const { partialObserver } = this;
if (partialObserver.error) {
try {
this.partialObserver.error(err);
partialObserver.error(err);
} catch (error) {
handleUnhandledError(error);
}
Expand All @@ -177,9 +179,10 @@ class ConsumerObserver<T> implements Observer<T> {
}

complete(): void {
if (this.partialObserver.complete) {
const { partialObserver } = this;
if (partialObserver.complete) {
try {
this.partialObserver.complete();
partialObserver.complete();
} catch (error) {
handleUnhandledError(error);
}
Expand Down