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

add explicit default group #3103

Merged

Conversation

LFSaw
Copy link
Member

@LFSaw LFSaw commented Aug 4, 2017

this fixes #3098

@LFSaw LFSaw self-assigned this Aug 4, 2017
@LFSaw LFSaw requested a review from telephon August 4, 2017 13:53
@LFSaw LFSaw changed the title add explicit default group. this fixes #3098 add explicit default group #3098 Aug 4, 2017
@LFSaw LFSaw changed the title add explicit default group #3098 add explicit default group Aug 4, 2017
@@ -256,6 +256,7 @@ BusPlug : AbstractFunction {
^this
};
if(bus.rate == \control) { "Can't monitor a control rate bus.".warn; monitor.stop; ^this };
group = group ?? {this.homeServer.defaultGroup};
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be simplified to ? without braces instead of ??.

Copy link
Member Author

Choose a reason for hiding this comment

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

no.
with ??, the latter is only evaluated when group is nil.

Copy link
Contributor

Choose a reason for hiding this comment

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

so if i'm understanding correctly, you should update the usage of ? below as well then

Copy link
Member Author

@LFSaw LFSaw Aug 4, 2017

Choose a reason for hiding this comment

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

hm... good question. of course, function evaluation costs as well.

TempoClock.default, the value after ? is an instance variable of TempoClock so it only just returns the value. Thus, in the case below, there's not much difference between ? and ??.
Compare:

bench{50000.do{[nil, 1].choose ? TempoClock.default}};
bench{50000.do{[nil, 1].choose ?? {TempoClock.default}}};

In the upper case, defaultGroup is a method of server which requires computation, hence we only want to evaluate it when it is needed.

bench{50000.do{[nil, 1].choose ? s.defaultGroup}};
bench{50000.do{[nil, 1].choose ?? {s.defaultGroup}}};

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, you're right! this is good to know. thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

? always evaluates the second operand, whether it will be used or not.

If I recall correctly, ?? inlines the following function if possible, so the cost should be less than pushing a function and calling value. In fact, I just checked: in something ?? { blah }, ?? compiles to a ControlOpcode that skips over the function's byte codes if the receiver is not nil. The cost of the jump should be a lot less.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the clarification, james. So my explanation was slightly off but the effect is the same :) (?)
I'll keep in mind {/**/}.def.dumpByteCode;:

{#[nil, 1].choose ?? {s.defaultGroup}}.def.dumpByteCodes

>>>
BYTECODES: (13)
  0   40       PushLiteral instance of Array (0x11fbdf828, size=2, set=2)
  1   C1 24    SendSpecialMsg 'choose'
  3   8F 17 00 05 ControlOpcode 5  (11)
  7   01 14    PushInstVarX 's'
  9   B0       TailCallReturnFromFunction
 10   A1 00    SendMsg 'defaultGroup'
 12   F2       BlockReturn
{#[nil, 1].choose ? s.defaultGroup}.def.dumpByteCodes

>>>
BYTECODES: (10)
  0   40       PushLiteral instance of Array (0x11fbdf278, size=2, set=2)
  1   C1 24    SendSpecialMsg 'choose'
  3   01 14    PushInstVarX 's'
  5   A1 00    SendMsg 'defaultGroup'
  7   8F 16    ControlOpcode
  9   F2       BlockReturn

But I have to say that I cannot read this... what's the ControlOpCode 5 (11) doing? That's the jump you're talking about?

@mossheim
Copy link
Contributor

mossheim commented Aug 4, 2017

will wait until @telephon has a chance to look at this before merging

Copy link
Contributor

@adcxyz adcxyz left a comment

Choose a reason for hiding this comment

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

brilliant, thanks for spotting that!

@adcxyz adcxyz merged commit a12dda8 into supercollider:master Aug 7, 2017
@LFSaw LFSaw deleted the topic/fix-NodeProxy-externalServer branch August 7, 2017 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants