mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-05 23:38:38 +09:00
Increase image cache size and adjust related parameters for improved performance
This commit is contained in:
parent
2e6dfbcc5e
commit
35aa94b223
3 changed files with 52 additions and 8 deletions
|
|
@ -1048,7 +1048,6 @@ imgLoader::CreateNewProxyForRequest(imgRequest* aRequest,
|
|||
class imgCacheExpirationTracker final
|
||||
: public nsExpirationTracker<imgCacheEntry, 3>
|
||||
{
|
||||
enum { TIMEOUT_SECONDS = 10 };
|
||||
public:
|
||||
imgCacheExpirationTracker();
|
||||
|
||||
|
|
@ -1057,10 +1056,45 @@ protected:
|
|||
};
|
||||
|
||||
imgCacheExpirationTracker::imgCacheExpirationTracker()
|
||||
: nsExpirationTracker<imgCacheEntry, 3>(TIMEOUT_SECONDS * 1000,
|
||||
: nsExpirationTracker<imgCacheEntry, 3>(
|
||||
Preferences::GetUint(
|
||||
"image.cache.entry_timeout_seconds",
|
||||
15) * 1000,
|
||||
"imgCacheExpirationTracker")
|
||||
{ }
|
||||
|
||||
static bool
|
||||
ShouldKeepRecentlyUsedAssetInCache(imgCacheEntry* aEntry)
|
||||
{
|
||||
RefPtr<imgRequest> request = aEntry->GetRequest();
|
||||
if (!request) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* mimeType = request->GetMimeType();
|
||||
if (!mimeType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Keep small, frequently reused static assets warm a bit longer.
|
||||
if (!nsCRT::strcmp(mimeType, IMAGE_SVG_XML) ||
|
||||
!nsCRT::strcmp(mimeType, IMAGE_PNG) ||
|
||||
!nsCRT::strcmp(mimeType, IMAGE_WEBP)) {
|
||||
const uint32_t kMaxWarmAssetBytes = 1024 * 1024;
|
||||
const uint32_t kRecentUseGraceSeconds = 120;
|
||||
|
||||
if (aEntry->GetDataSize() <= kMaxWarmAssetBytes) {
|
||||
uint32_t now = SecondsFromPRTime(PR_Now());
|
||||
uint32_t touched = aEntry->GetTouchedTime();
|
||||
if (now >= touched && (now - touched) <= kRecentUseGraceSeconds) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
imgCacheExpirationTracker::NotifyExpired(imgCacheEntry* entry)
|
||||
{
|
||||
|
|
@ -1068,6 +1102,12 @@ imgCacheExpirationTracker::NotifyExpired(imgCacheEntry* entry)
|
|||
// mechanism doesn't.
|
||||
RefPtr<imgCacheEntry> kungFuDeathGrip(entry);
|
||||
|
||||
if (ShouldKeepRecentlyUsedAssetInCache(entry)) {
|
||||
entry->Touch();
|
||||
entry->Loader()->VerifyCacheSizes();
|
||||
return;
|
||||
}
|
||||
|
||||
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
|
||||
RefPtr<imgRequest> req = entry->GetRequest();
|
||||
if (req) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue