I made a patch to a programming language run-time to cache the results of hashing a string in the string object, so that it is just retrieved the next time it is required.
However, I'm not convinced there is any worthwhile benefit, and the feature comes at an opportunity cost. Heap objects have only four pointer-sized words of storage available, so dedicating a word for a hash code is a big deal. The patch includes some changes to make this word available in the first place; that part of the patch could be retained while the newly available storage word is put to a more beneficial use than storing a hash code.
I know Java runtimes store hash codes in strings, but I've never worked in Java. Searching around, there are plenty of explanations about how it works, and the obvious benefit of not having to calculate a hash twice on the same object, but a rationale for doing it is elusive: what is it that Java programs do with strings that makes it important to dedicate a word to caching the hash value?
It seems to me that if the same string object (not the same string) is asked for its hash value a large number of times, there is something wrong with the program's approach.