[Vm-dev] Is it important to fill identity-hash for Floats?

Igor Stasenko siguctua at gmail.com
Wed Jul 31 02:17:27 UTC 2013

On 30 July 2013 23:37, Chris Muller <asqueaker at gmail.com> wrote:
> On Mon, Jul 29, 2013 at 5:23 PM, Bert Freudenberg <bert at freudenbergs.de> wrote:
>> On 2013-07-29, at 23:59, Igor Stasenko <siguctua at gmail.com> wrote:
>>> just a thought..
>>> imo using identity hash field for instances of Float while probable,
>>> but in fact really impractical.
>>> in that sense, what you think about removing filling the identity hash field
>>> and leave it always == 0.. saving some instructions to make float
>>> allocation a bit faster?
>>> i am talking about
>>> genAllocFloatValue: dpreg into: resultReg scratchReg: scratch1
>>> scratchReg: scratch2
>> IMHO, turning Floats into the only objects in the system that cause severe collisions in IdentitySets / Dictionaries should not be done lightly. It's a step away from "every object is equal" which I think is an important principle.
> +1.  I recently was investigating memory consumption in a large
> application image and discovered > 100MB in Float instances..!!  But
> guess what, many many of them were the same number (0.0, 1.0, 100.0,
> -100.0, and several others had many occurrences) -- prompting me to
> wonder whether I should try to canonicalize them upon materialization,
> via an IdentityDictionary..
> I haven't tried it yet but.. if their identityHash'es were all 0 then
> it'd be pointless to try.

right now it will be pointless as well, since

0.0 identityHash ~= 0.0 identityHash

and for canonization you have to use Dictionary which uses #hash, not
identity hash.

> So I like your other idea about using the float itself as the
> identityHash, however that would be done, at least they'd be unique
> and consistent.

hashes are not unique by definition, they are just need to be "unique
enough" to not
collide much often.

So far, there is only one dictionary which uses floats as keys:

(Dictionary allSubInstances select: [:dict |
	dict keys anySatisfy: [:key | key isFloat ]
) size

That the only dictionary used in Pharo by SHTextStyler
and i think it rather bug/coincidence, since pixel height usually
integer number.

Ah, yes.. and this is dictionary, not identity dictionary, using #hash
for keys anyways.

(Set allSubInstances select: [:set |
	set anySatisfy: [:key | key isFloat ]
) size


But i agree, i can imagine that for things like Magma, you need to use
them as keys..

Best regards,
Igor Stasenko.

More information about the Vm-dev mailing list