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
add explicit default group #3103
Conversation
@@ -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}; |
There was a problem hiding this comment.
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 ??
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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}}};
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
will wait until @telephon has a chance to look at this before merging |
There was a problem hiding this 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!
this fixes #3098