Bug 249915 - Don't update MemoryCache during drawImage if the image is decoded into DiscardableMemory
Summary: Don't update MemoryCache during drawImage if the image is decoded into Discar...
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-12-27 17:51 PST by Ahmad Saleem
Modified: 2023-01-31 08:51 PST (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ahmad Saleem 2022-12-27 17:51:34 PST
Hi Team,

While going through Blink commit, I came across following performance optimization done for improving Canvas benchmarks on mobile devices.

Blink Commit - https://chromium.googlesource.com/chromium/blink/+/53145cb436d6033ee2c3d0d1974ba719642c320f

WebKit GitHub Source - https://github.com/WebKit/WebKit/blob/55b3d145b200da84bc53e06eb13832850e0579c0/Source/WebCore/loader/cache/CachedImage.cpp#L655

I am not sure whether we need this or not but I just wanted to raise this for discussion purposes whether we can use something similar to get from this commit for any future optimisation.

For discussion only.

Thanks!
Comment 1 Radar WebKit Bug Importer 2023-01-03 17:52:17 PST
<rdar://problem/103855904>
Comment 2 Darin Adler 2023-01-30 15:10:57 PST
Is "discardable memory" a concept we have in WebKit too?
Comment 3 Ahmad Saleem 2023-01-30 15:13:53 PST
(In reply to Darin Adler from comment #2)
> Is "discardable memory" a concept we have in WebKit too?

Searching "DiscardableMemory" in GitHub does not show anything and I tried this on Local branch few days back and tried some Canvas benchmark but it does not seems to increase fps. My testing could be flawed and might not be targeting right benchmarks (I was just googling and opening StackOverflow benchmark mentioning Webkit being slow on Canvas) but this is what I have tried so far with my local testing etc.

I don't know how much helpful it would be. Sorry, if it isn't much.
Comment 4 Alexey Proskuryakov 2023-01-31 08:51:08 PST
While I don't have an answer about "discardable memory", I don't think that this optimization applies to WebKit, because CachedResource::didAccessDecodedData is already quick when the resource is not in cache:


void CachedResource::didAccessDecodedData(MonotonicTime timeStamp)
{
    m_lastDecodedAccessTime = timeStamp;
    
    if (allowsCaching() && inCache()) {
        auto& memoryCache = MemoryCache::singleton();
        if (memoryCache.inLiveDecodedResourcesList(*this)) {
            memoryCache.removeFromLiveDecodedResourcesList(*this);
            memoryCache.insertInLiveDecodedResourcesList(*this);
        }
        memoryCache.pruneSoon();
    }
}