Hi,

Magritte and my TagLengthValue (TLV) both use 
>>#instVarNamed:/>>#instVarNamed:put: to read and write from an object. I was 
just running >>#bench on my SMPP library and noticed that besides Spur Pharo5 
is slower than Pharo3.


I added this to PointerLayout:

>># instVarIndexFor: aString ifAbsent: aBlockClosure 
        | idx |
        idx := 1.
        slotScope do: [:each |
                each isVisible ifTrue: [
                        each name = aString ifTrue: [^idx].
                        idx := idx +1]].
        ^aBlockClosure value

and modified ClassDescription/TClassDescription to use it:

"protocol: instance variables"
instVarIndexFor: instVarName ifAbsent: aBlock
        "Answer the index of the named instance variable."

        | index |
        index := self classLayout instVarIndexFor: instVarName ifAbsent: [0].
        index = 0 ifTrue: 
                [^self superclass == nil 
                        ifTrue: [aBlock value]
                        ifFalse: [self superclass instVarIndexFor: instVarName 
ifAbsent: aBlock]].
        ^self superclass == nil         
                ifTrue: [index]
                ifFalse: [index + self superclass instSize]


The speed-up comes from filtering allSlots to allVisibleSlots (and creating an 
Array), then collecting the slot names and finally searching the name. Does it 
make sense to integrate such speed-ups?


cheers
        holger


Reply via email to