[squeak-dev] isKindOf: in Morphic code...

tim Rowledge tim at rowledge.org
Mon Jul 4 21:10:30 UTC 2016


> On 04-07-2016, at 1:59 PM, Tobias Pape <Das.Linux at gmx.de> wrote:
> 
> 
> On 04.07.2016, at 22:44, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> 
>> Hi All, Hi Marcel,
>> 
>>    when I see code like this, and there's a lot of it in Morphic,
>> 
>> !Flaps class methodsFor: 'testing' stamp: 'mt 5/17/2016 14:17'!
>> anyFlapsVisibleIn: aWorld
>> 
>>        aWorld submorphsDo: [:m |
>>                (m isKindOf: FlapTab) ifTrue: [^ true]].
>> 
>>        ^ false! !
>> 
>> I think this is performance thrown on the floor (isKindOf: is awfully slow, especially in huge hierarchies like Morphic, and bad design, restricting one to a concrete class).  And I think that Morph provides a perfect place to put an extension that doesn't pollute Object.  So I would like to see 
>> 
>> anyFlapsVisibleIn: aWorld
>> 
>>        aWorld submorphsDo:
>>               [:m| m isFlapTab ifTrue: [^true]].
>>        ^ false! !
>> 
>> with the emphasis on isFlapTab ;-)
> 
> Well, class testing seems to be a Morphic pattern, given #findA: (alias #submorphOfClass:)

It is, and it’s horrible. One of the major things I did to speed up Scratch was fixing hundreds of badly placed isKindOf: sends. Ideally one can find a better algorithm and avoid the issue completely in some places. 
Not quite so good is adding lots of isThingummy methods but at least that is faster! This is at least architecturally better since there are plenty of cases where simple class inheritance is not sufficient as a test   because several disjoint classes provide a facility. You *really* don’t want to see multiple isKindOf’s in side an important loop!

I suspect that there are a lot of places where we should *not* simply use the list of submorphs and scan it with isKindOf type tests but instead keep more precise track of relevant submorphs. 

tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
Strange OpCodes: SD: Self Destruct




More information about the Squeak-dev mailing list