Installing trait blow the method def in hierarchy
Hi, Iâve noticed that if you install a trait on a class and a trait defines explicit requirement method, and this method is defined in a super class, it is being looked up during execution through #explicitRequirement method. It was slowing down my execution by almost 20%. Is there a special way to use a Trait to avoid that, or itâs work-in-progress solution? Uko
2015-05-12 12:06 GMT+02:00 Yuriy Tymchuk <yuriy.tymchuk@me.com>:
Hi,
Iâve noticed that if you install a trait on a class and a trait defines explicit requirement method, and this method is defined in a super class, it is being looked up during execution through #explicitRequirement method. It was slowing down my execution by almost 20%. Is there a special way to use a Trait to avoid that, or itâs work-in-progress solution?
I find this behavior questionable, when did this change? ( I thought self explicitRequirement always signals an error and does not try to find the method in the superclass chain). Anyway, if you want to use the super class method, you can just remove the method from the trait usage. ASuperClass subclass: #MySubclass uses: ATrait - {#theMethodDefinedInSuperclassAndTrait } instanceVariableNames: '' classVariableNames: '' category: '' regards Nicolai
Uko
On 13 May 2015, at 09:25, Nicolai Hess <nicolaihess@web.de> wrote:
2015-05-12 12:06 GMT+02:00 Yuriy Tymchuk <yuriy.tymchuk@me.com <mailto:yuriy.tymchuk@me.com>>: Hi,
Iâve noticed that if you install a trait on a class and a trait defines explicit requirement method, and this method is defined in a super class, it is being looked up during execution through #explicitRequirement method. It was slowing down my execution by almost 20%. Is there a special way to use a Trait to avoid that, or itâs work-in-progress solution?
I find this behavior questionable, when did this change? ( I thought self explicitRequirement always signals an error and does not try to find the method in the superclass chain). Anyway, if you want to use the super class method, you can just remove the method from the trait usage.
ASuperClass subclass: #MySubclass uses: ATrait - {#theMethodDefinedInSuperclassAndTrait } instanceVariableNames: '' classVariableNames: '' category: â'
Good to know, thanks. I donât know the philosophy behind this case, but from my point of view - trait requires a method, and the class has it, itâs just that the method is defined higher in the hierarchy. Uko
regards Nicolai
Uko
On 13 May 2015, at 10:42, Yuriy Tymchuk <yuriy.tymchuk@me.com> wrote:
On 13 May 2015, at 09:25, Nicolai Hess <nicolaihess@web.de <mailto:nicolaihess@web.de>> wrote:
2015-05-12 12:06 GMT+02:00 Yuriy Tymchuk <yuriy.tymchuk@me.com <mailto:yuriy.tymchuk@me.com>>: Hi,
Iâve noticed that if you install a trait on a class and a trait defines explicit requirement method, and this method is defined in a super class, it is being looked up during execution through #explicitRequirement method. It was slowing down my execution by almost 20%. Is there a special way to use a Trait to avoid that, or itâs work-in-progress solution?
I find this behavior questionable, when did this change? ( I thought self explicitRequirement always signals an error and does not try to find the method in the superclass chain). Anyway, if you want to use the super class method, you can just remove the method from the trait usage.
ASuperClass subclass: #MySubclass uses: ATrait - {#theMethodDefinedInSuperclassAndTrait } instanceVariableNames: '' classVariableNames: '' category: â'
Good to know, thanks. I donât know the philosophy behind this case, but from my point of view - trait requires a method, and the class has it, itâs just that the method is defined higher in the hierarchy.
I agree, this is the behavior I would expect too. From this point of view, the problem is the 20% slowdown. A solution would be that traits does not install explicit requirements in their users if suitable methods are already in their hierarchy. Then traits needs to listen to method addition/removal announcements to install/remove the explicit requirement methods in their users accordingly. Another solution is to never install explicit requirement methods and have a modified version of doesNotUnderstand: that detect when the missing method is an explicit requirement. So we have four solution: - explicit requirements does not override methods in the hierarchies of the trait users: 1. current situation: nothing to do but 20% slowdown (but no slowdown by removing the explicit requirement from the trait composition). 2. automatic installation/removal of explicit requirement in traits users: adds more complexity in trait installation logic but transparent to user. 3. dynamic detection of explicit requirement in doesNotUnderstand: slower DNU but still transparent to user. - explicit requirements always override methods in the hierarchies of the trait users: 4. explicit resolution by removing overriding explicit requirements from trait compositions: less magic but maybe confusing for users I vote for 2 (then 1, 3, 4). Camille
Uko
regards Nicolai
Uko
Any idea where the slowdown comes from? 20% makes it easily detectable Alexandre
Le 12 mai 2015 à 07:06, Yuriy Tymchuk <yuriy.tymchuk@me.com> a écrit :
Hi,
Iâve noticed that if you install a trait on a class and a trait defines explicit requirement method, and this method is defined in a super class, it is being looked up during execution through #explicitRequirement method. It was slowing down my execution by almost 20%. Is there a special way to use a Trait to avoid that, or itâs work-in-progress solution?
Uko
On 14 May 2015, at 11:46, Alexandre Bergel <alexandre.bergel@me.com> wrote:
Any idea where the slowdown comes from? 20% makes it easily detectable
It comes from the method resolution and invocation in Object>>#explicitRequirement. Camille
Alexandre
Le 12 mai 2015 à 07:06, Yuriy Tymchuk <yuriy.tymchuk@me.com> a écrit :
Hi,
Iâve noticed that if you install a trait on a class and a trait defines explicit requirement method, and this method is defined in a super class, it is being looked up during execution through #explicitRequirement method. It was slowing down my execution by almost 20%. Is there a special way to use a Trait to avoid that, or itâs work-in-progress solution?
Uko
Ok, thanks Alexandre
On May 14, 2015, at 5:52 AM, Camille <camille.teruel@gmail.com> wrote:
On 14 May 2015, at 11:46, Alexandre Bergel <alexandre.bergel@me.com> wrote:
Any idea where the slowdown comes from? 20% makes it easily detectable
It comes from the method resolution and invocation in Object>>#explicitRequirement.
Camille
Alexandre
Le 12 mai 2015 à 07:06, Yuriy Tymchuk <yuriy.tymchuk@me.com> a écrit :
Hi,
Iâve noticed that if you install a trait on a class and a trait defines explicit requirement method, and this method is defined in a super class, it is being looked up during execution through #explicitRequirement method. It was slowing down my execution by almost 20%. Is there a special way to use a Trait to avoid that, or itâs work-in-progress solution?
Uko
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
participants (4)
-
Alexandre Bergel -
Camille -
Nicolai Hess -
Yuriy Tymchuk