[ENH] BehaviorHashEnh

sr at evolgo.de sr at evolgo.de
Tue Jun 22 18:53:41 UTC 2004


"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
--------"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BehaviorHashEnh.cs.gz
Type: application/octet-stream
Size: 1166 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040622/27efbbf1/BehaviorHashEnh.cs.obj


More information about the Squeak-dev mailing list