Improve effectiveness of function-level caching
Created attachment 173150 [details] Patch
Committed r133975: <http://trac.webkit.org/changeset/133975>
Comment on attachment 173150 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=173150&action=review > Source/JavaScriptCore/runtime/CodeCache.h:55 > +template <typename KeyType, typename EntryType, int CacheSize> class Thingy { Thingy? No, please use a real name. RandomEvictionCache maybe? > Source/JavaScriptCore/runtime/CodeCache.h:59 > + : m_randomGenerator((static_cast<uint32_t>(randomNumber() * UINT32_MAX))) Incorrect indentation here. > Source/JavaScriptCore/runtime/CodeCache.h:76 > + size_t newIndex = m_randomGenerator.getUint32() % CacheSize; This is not an even distribution across the cache; it will be slightly biased towards lower numbers unless the cache size is a power of 2. It would be better to make WeakRandom have a function to help you get even distribution.
(In reply to comment #3) > (From update of attachment 173150 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=173150&action=review > > > Source/JavaScriptCore/runtime/CodeCache.h:55 > > +template <typename KeyType, typename EntryType, int CacheSize> class Thingy { > > Thingy? No, please use a real name. RandomEvictionCache maybe? Doh! > > > Source/JavaScriptCore/runtime/CodeCache.h:59 > > + : m_randomGenerator((static_cast<uint32_t>(randomNumber() * UINT32_MAX))) > > Incorrect indentation here. Whoops > > > Source/JavaScriptCore/runtime/CodeCache.h:76 > > + size_t newIndex = m_randomGenerator.getUint32() % CacheSize; > > This is not an even distribution across the cache; it will be slightly biased towards lower numbers unless the cache size is a power of 2. It would be better to make WeakRandom have a function to help you get even distribution. The bias is not the worst thing in the world, adding the branches to get unbiased behaviour seems overkill.