Bug 101667 - Improve effectiveness of function-level caching
Summary: Improve effectiveness of function-level caching
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Oliver Hunt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-08 16:57 PST by Oliver Hunt
Modified: 2012-11-08 18:43 PST (History)
0 users

See Also:


Attachments
Patch (16.38 KB, patch)
2012-11-08 17:01 PST, Oliver Hunt
fpizlo: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Hunt 2012-11-08 16:57:21 PST
Improve effectiveness of function-level caching
Comment 1 Oliver Hunt 2012-11-08 17:01:25 PST
Created attachment 173150 [details]
Patch
Comment 2 Oliver Hunt 2012-11-08 17:13:08 PST
Committed r133975: <http://trac.webkit.org/changeset/133975>
Comment 3 Darin Adler 2012-11-08 18:03:58 PST
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.
Comment 4 Oliver Hunt 2012-11-08 18:43:21 PST
(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.