Mantis - Squeak
Viewing Issue Advanced Details
1632 Kernel minor always 08-08-05 21:53 02-16-06 17:40
KenCausey  
 
normal  
closed  
fixed  
none    
none 3.9  
0001632: [ENH] BehaviorHashEnh
sr@evolgo.de:

"Change Set: BehaviorHashEnh v1.1
Date: 22 June 2004
Author: Stephan Rudlof

Improves the default Object>>hash for Behaviors by installing
Behavior>>hash. String>>hash has been changed a little to avoid infinite
recursion (without changing its semantics).
All is done in the postscript.

Important
-----------
This is a special changeset: Do not export and import this changeset
again after importing it the first time! Then the methods are not
installed alone in the postscript anymore, leading to serious problems!
-----------

Rationale: Object>>hash calling ProtoObject>>identityHash gives poor
results for Behaviors. Therefore a new Behavior>>hash using Symbol>>hash
or String>>hash (the latter slightly changed to avoide infinite
recursion) will be installed.

Consequences:
- It speeds up Set/Dictionary operations with Behaviors a lot (see
below).
- The main consequence for other objects as Behaviors seems to be a
changed hash if they use
    self species hash
as a start value for computing their hash.
But AFAICS this doesn't hurt, since in most cases (non meta classes as
species) it maps to Symbol>>hash, which is fast.

Test:
doIt
    | allClasses allClassesSet block |
    allClasses := Smalltalk allClasses.
    block _ [allClassesSet _ allClasses asSet.
            [allClasses do: [:class | allClassesSet remove: class]] timeToRun].
    {block value. block value. block value}
before and after filing in this cs.
To see the problem again just doIt
    | allClasses allClassesSet block |
    allClasses := Smalltalk allClasses.
    block _ [allClassesSet _ allClasses asIdentitySet.
            [allClasses do: [:class | allClassesSet remove: class]] timeToRun].
    {block value. block value. block value}.

Future: Best would probably be a better identityHash with more bits
(possibly in V4?).

PS: I've been stumbled over BrowserEnvironmentTest>>testAllClassesDo,
which is dog slow without this cs.

History
--------
- v1.1: changed cs comment
- without v no: original version
--------"
 BehaviorHashEnh.cs.gz [^] (1,166 bytes) 08-08-05 21:53

Notes
(0002207)
KenCausey   
08-08-05 21:54   
karl.ramberg@chello.se:

"[er][et][sm][cd] looks good"
(0002208)
KenCausey   
08-08-05 21:56   
ducasse@iam.unibe.ch:

"can somebody else have a look at this enh.

I run the "tests"

| allClasses allClassesSet block |
    allClasses := Smalltalk allClasses.
    block _ [allClassesSet _ allClasses asSet.
            [allClasses do: [:class | allClassesSet remove: class]] timeToRun].
    {block value. block value. block value}
    

before and after filing in this cs.
To see the problem again just doIt
    | allClasses allClassesSet block |
    allClasses := Smalltalk allClasses.
    block _ [allClassesSet _ allClasses asIdentitySet.
            [allClasses do: [:class | allClassesSet remove: class]] timeToRun].
    {block value. block value. block value}.
    
    
after loading I got
    -> #(64 57 63)

To see the problem again just doIt
    -> #(34 33 39)
    

So I'm confused because I thought this would be the opposite so I may be
too tired."
(0002209)
KenCausey   
08-08-05 21:57   
=?ISO-8859-1?Q?st=E9phane_ducasse?= <ducasse@iam.unibe.ch>:

"with 3.8 6273

I get | allClasses allClassesSet block |
    allClasses := Smalltalk allClasses.
    block _ [allClassesSet _ allClasses asSet.
            [allClasses do: [:class | allClassesSet remove: class]] timeToRun].
    {block value. block value. block value}
  #(51 48 53)

and nearly the same in 6208

Stef

could you check because something certainly changed."
(0002210)
KenCausey   
08-08-05 22:00   
Stephan Rudlof <sr@evolgo.de>:

"now I've tested with Squeak3.8alpha #6285:
and the results remain the same for me as for Squeak3.7!
With fileIn of the cs or doIt of the postscript in the cs directly:
always the same.

I don't understand your results.


Please give me your results exactly as I've done them below (two doIts
before and two other ones after fileIn of the cs, the *first* and
*second* doIt (of the two) are *different*!).

I have tried to be very explicit in my explanations, sine I just have
the idea that we are testing different things.


Any other takers?

My results:

*first* doIt
    | allClasses allClassesSet block |
    allClasses := Smalltalk allClasses.
    block _ [allClassesSet _ allClasses asSet.
            [allClasses do: [:class | allClassesSet remove: class]] timeToRun].
    {block value. block value. block value}
 #(6840 6863 6823) #(6988 6907 6862) "before"
 #(199 204 200) #(203 219 206) "after fileIn"
    
*second* doIt
    | allClasses allClassesSet block |
    allClasses := Smalltalk allClasses.
    block _ [allClassesSet _ allClasses asIdentitySet.
            [allClasses do: [:class | allClassesSet remove: class]] timeToRun].
    {block value. block value. block value}.
 #(3112 3166 3108) #(3152 3160 3129) "before"
 #(3196 3225 3186) #(3193 3181 3163) "after fileIn"


My cs has been (you can also doIt the postscript manually):

'From Squeak3.7beta of ''1 April 2004'' [latest update: #5963] on 22
June 2004 at 8:51:57 pm'!
"Change Set: BehaviorHashEnh v1.1
Date: 22 June 2004
Author: Stephan Rudlof

Improves the default Object>>hash for Behaviors by installing
Behavior>>hash. String>>hash has been changed a little to avoid infinite
recursion (without changing its semantics).
All is done in the postscript.

Important
-----------
This is a special changeset: Do not export and import this changeset
again after importing it the first time!! Then the methods are not
installed alone in the postscript anymore, leading to serious problems!!
-----------

Rationale: Object>>hash calling ProtoObject>>identityHash gives poor
results for Behaviors. Therefore a new Behavior>>hash using Symbol>>hash
or String>>hash (the latter slightly changed to avoide infinite
recursion) will be installed.

Consequences:
- It speeds up Set/Dictionary operations with Behaviors a lot (see below).
- The main consequence for other objects as Behaviors seems to be a
changed hash if they use
    self species hash
as a start value for computing their hash.
But AFAICS this doesn't hurt, since in most cases (non meta classes as
species) it maps to Symbol>>hash, which is fast.

Test:
doIt
    | allClasses allClassesSet block |
    allClasses := Smalltalk allClasses.
    block _ [allClassesSet _ allClasses asSet.
            [allClasses do: [:class | allClassesSet remove: class]] timeToRun].
    {block value. block value. block value}
before and after filing in this cs.
To see the problem again just doIt
    | allClasses allClassesSet block |
    allClasses := Smalltalk allClasses.
    block _ [allClassesSet _ allClasses asIdentitySet.
            [allClasses do: [:class | allClassesSet remove: class]] timeToRun].
    {block value. block value. block value}.

Future: Best would probably be a better identityHash with more bits
(possibly in V4?).

PS: I've been stumbled over BrowserEnvironmentTest>>testAllClassesDo,
which is dog slow without this cs.

History
--------
- v1.1: changed cs comment
- without v no: original version
--------"!

"Postscript:
Compile String and Behavior >>hash here, since compilation has to be
tight together with rehashing Sets possibly containing objects with
changed >>hash."

String compile:
'hash
    "#hash is implemented, because #= is implemented"

    ^ByteArray
        hashBytes: self
        startingWith: self species identityHash'.
            
Set quickRehashAllSets.

Behavior compile:
'hash
    ^ self name hash'.
    
Set quickRehashAllSets.
!"
(0002211)
KenCausey   
08-08-05 22:02   
I loaded this changeset in 3.8-6665-basic without errors but did not test further.
(0003883)
MarcusDenker   
02-16-06 17:40   
added to 3.9a