JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.65k stars 5.48k forks source link

cache hash values for longer strings #35065

Open JeffBezanson opened 4 years ago

JeffBezanson commented 4 years ago

For strings over a certain size threshold, it seems like it would be an easy win to allocate an extra word at the end of the string data to cache its hash value. For example, this could dramatically speed up de-duplication in the serializer when there are many references to the same large string object.

oscardssmith commented 4 years ago

Would it make sense to add this to all large immutable objects?

vtjnash commented 4 years ago

Other objects are less likely to be used as a hash and/or large.

I guess this brings up the question too of whether we should cache length and isascii and isvalid and other common queries with O(1) storage for these larger strings too.

JeffBezanson commented 4 years ago

Yep, see #33712.