pharo icon indicating copy to clipboard operation
pharo copied to clipboard

Consider caching or hard coding String initialHash

Open marschall opened this issue 2 years ago • 1 comments

Describe the request String >> #hash uses ByteString hash as an initial hash. This should be cached or hard coded.

Expected behavior String >> #hash sends ByteString hash to compute an initial hash. This sometimes shows up during profiling. ByteString hash has be a constant value for an image otherwise all collections would have to be rehashed. Behavior implements #basicIdentityHash and uses primitive 175 to return the classes index in the class table. This returns 13312 in my image.

It looks like the idea was once to use self class hash or similar so that ByteString and WideString would hash differently but this was abandoned due to the need for rehashing.

Instead of sending ByteString hash every time we hash a string we can either cache this value or use hard code value.

Expected development cost

As you know nothing happens magically, so do you have an idea of the development effort required?

Depends a bit on the approach chosen. Simply hard coding a value in String >> #hash should not be too much effort. Caching depends a bit on where and how to cache, the easiest would probably be a class variable.

In addition, are you willing to help because after all Pharo is yours too?

Sure. If there is consensus what should be done how.

Version information:

  • OS: any
  • Version: any
  • Pharo Version: at least 10 and 11

marschall avatar Aug 22 '22 08:08 marschall

Thanks for opening your first issue! Please check the CONTRIBUTING documents for some tips about which information should be provided. You can find information of how to do a Pull Request here: https://github.com/pharo-project/pharo/wiki/Contribute-a-fix-to-Pharo

GitHub
Pharo is a dynamic reflective pure object-oriented language supporting live programming inspired by Smalltalk. - Contribute a fix to Pharo · pharo-project/pharo Wiki

welcome[bot] avatar Aug 22 '22 08:08 welcome[bot]

Hi @marschall I did a PR to propose to cache it

jecisc avatar Feb 03 '23 12:02 jecisc