Mantis - Squeak
Viewing Issue Advanced Details
7166 Kernel tweak always 08-27-08 21:43 04-18-10 21:59
Keith_Hodges  
 
normal  
closed 3.10.2  
open  
none    
none 3.10.2bc  
0007166: speedup allSelectors add allSelectorsBelow:
Firstly #allSelectors inefficiently creates multiple intermediate collections. Refactoring this yields a 27% speed improvement.

Secondly many users of #allSelectors forget that when applied to the class side it doesnt stop at ProtoObject class, it continues to Class ClassDescription, Behavior, Object and ProtoObject. This is catered for by adding #allSelectorsBelow:

Magritte and SUnit are heavy users which benefit.
child of 0007423new  Fixes included in Level Playing Field 
 Speedup-AllSelectors-M7166.cs [^] (596 bytes) 08-27-08 21:43
 Speedup-AllSelectors-M7166.1.cs [^] (909 bytes) 09-28-08 16:26

Notes
(0012533)
Keith_Hodges   
08-27-08 21:44   
"fix begin"
Installer mantis bug: 7166 fix: 'Speedup-AllSelectors-M7166.cs'.
"fix end"
(0012702)
Damien Cassou   
09-28-08 14:01   
I've sent that fix to PharoInbox. I replaced 'withAllSuperclasses do:' by 'withAllSuperclassDo:' to avoid the creation of another collection.
(0012703)
Damien Cassou   
09-28-08 14:47   
I also added the following test:

testAllSelectors
  self assert: ProtoObject allSelectors = ProtoObject selectors.
  self assert: Object allSelectors = (Object selectors union: ProtoObject selectors).
  self assert: (Object allSelectorsBelow: ProtoObject) = (Object selectors).
(0012704)
Damien Cassou   
09-28-08 16:26   
"fix begin"
Installer mantis bug: 7166 fix: 'Speedup-AllSelectors-M7166.1.cs'.
"fix end"
(0013414)
nicolas cellier   
11-29-09 20:27   
In trunk, this doesn't make much difference as long as selectors are Array.
This version is even slightly faster than allSelectorsBelow:

Behavior>>allSelectors
    "Answer all selectors understood by instances of the receiver"

    ^(Array streamContents: [:strm |
        self withAllSuperclassesDo:
            [:aClass | strm nextPutAll: aClass selectors]]) asIdentitySet

{
[EToyProjectQueryMorph allSelectors] bench.
[EToyProjectQueryMorph allSelectorsBelow: nil] bench.
}
#('59.4691678307723 per second.' '53.64978061428 per second.')

Yes, we create intermediary collections, but cheap ones: Array...
(0013420)
leves   
12-02-09 20:02   
Even better without the intermediate collections:

Behavior >> allSelectors
    "Answer all selectors understood by instances of the receiver"

    ^(Array streamContents: [ :stream |
        self withAllSuperclassesDo: [ :aClass |
            aClass selectorsDo: [ :each |
                stream nextPut: each ] ] ]) asIdentitySet
(0013424)
leves   
12-03-09 04:24   
Added to the trunk with Kernel-ul.319