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

fix(Subscriber): do not call complete with undefined value param #2559

Merged
merged 1 commit into from
May 9, 2017

Conversation

kwonoj
Copy link
Member

@kwonoj kwonoj commented Apr 16, 2017

Description:
This PR makes to call observer's complete function without delivering one param as undefined value all times. While observer is requested to follow its contract interfaces, change seems trivial to avoid this behavior in code as well.

I think this is non-breaking changes maybe?

Related issue (if exists):

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.644% when pulling 4bae1c0 on kwonoj:fix-subscribe-complete into e387113 on ReactiveX:master.

try {
fn.call(this._context, value);
fn.call(this._context, ...value);
Copy link
Member

@trxcllnt trxcllnt Apr 27, 2017

Choose a reason for hiding this comment

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

@kwonoj since this is a hot code path, can we avoid allocating the rest args Array with a third boolean argument as a flag?

Copy link
Member Author

Choose a reason for hiding this comment

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

mean like __tryOrUnsub(fn: Function, value: Array<any>, passValue: boolean)?

Copy link
Member

Choose a reason for hiding this comment

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

yes, exactly

Copy link
Member Author

Choose a reason for hiding this comment

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

I can, it's eventually same. I just picked rest operator for simplicity of readability.

Copy link
Member

@trxcllnt trxcllnt Apr 28, 2017

Choose a reason for hiding this comment

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

@kwonoj yeah but it transpiles down to an Array allocation + apply call, which is 20-25x slower than the equivalent conditional call in this jsperf test. so it's important in this code path.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah yes, what I meant of same is the perspective of consequences only without perf differences. again, I just picked it up for readability at the moment.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0004%) to 97.644% when pulling 10dcdd4 on kwonoj:fix-subscribe-complete into e69d876 on ReactiveX:master.

@@ -234,11 +234,13 @@ class SafeSubscriber<T> extends Subscriber<T> {
if (!this.isStopped) {
const { _parentSubscriber } = this;
if (this._complete) {
const wrappedComplete = () => this._complete.call(this._context);
Copy link
Member Author

Choose a reason for hiding this comment

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

@trxcllnt what about this approach? create one fn closure for complete only, and let __try... avoid any branching (if, or rest operator...). There is overhead to create one additional closure, but only for completion and will not impact next.

Copy link
Member

Choose a reason for hiding this comment

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

@kwonoj that looks great! I like how it removes the branching in the next case

const sub1 = new Subscriber(observer);
sub1.complete();

expect(observer.complete.firstCall.args).to.empty;
Copy link
Member

Choose a reason for hiding this comment

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

.to.be.empty

Copy link
Member

Choose a reason for hiding this comment

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

Also, I don't know enough about sinon to know if this is how we check this. It seems like a more straight forward test just using a plain object and expect(arguments.length).to.equal(0) would do.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, probably simple test like this could be achieved in those way. I'll update test.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0004%) to 97.644% when pulling 56ce619 on kwonoj:fix-subscribe-complete into 83ebe90 on ReactiveX:master.

@kwonoj
Copy link
Member Author

kwonoj commented May 7, 2017

test cases are updated as suggested.

@benlesh benlesh merged commit 3d63de2 into ReactiveX:master May 9, 2017
@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
@kwonoj kwonoj deleted the fix-subscribe-complete branch October 4, 2019 05:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

complete() always called with single, undefined argument (differs from prior Rx behavior)
4 participants