#399: tune up HTTP cache M1248003 M1248389

This commit is contained in:
Cameron Kaiser 2018-04-26 21:01:55 -07:00
parent 9d1d17ec99
commit 2bc560a930
4 changed files with 30 additions and 3 deletions

View File

@ -69,6 +69,7 @@ public:
CacheIndexEntryAutoManage(const SHA1Sum::Hash *aHash, CacheIndex *aIndex)
: mIndex(aIndex)
, mOldRecord(nullptr)
, mOldFrecency(0)
, mDoNotSearchInIndex(false)
, mDoNotSearchInUpdates(false)
{
@ -79,6 +80,7 @@ public:
mIndex->mIndexStats.BeforeChange(entry);
if (entry && entry->IsInitialized() && !entry->IsRemoved()) {
mOldRecord = entry->mRec;
mOldFrecency = entry->mRec->mFrecency;
}
}
@ -104,6 +106,8 @@ public:
mIndex->ReplaceRecordInIterators(mOldRecord, entry->mRec);
mIndex->RemoveRecordFromFrecencyArray(mOldRecord);
mIndex->InsertRecordToFrecencyArray(entry->mRec);
} else if (entry->mRec->mFrecency != mOldFrecency) {
mIndex->mFrecencyArraySorted = false;
}
} else {
// both entries were removed or not initialized, do nothing
@ -147,6 +151,7 @@ private:
const SHA1Sum::Hash *mHash;
RefPtr<CacheIndex> mIndex;
CacheIndexRecord *mOldRecord;
uint32_t mOldFrecency;
bool mDoNotSearchInIndex;
bool mDoNotSearchInUpdates;
};
@ -246,6 +251,7 @@ CacheIndex::CacheIndex()
, mRWBufSize(0)
, mRWBufPos(0)
, mJournalReadSuccessfully(false)
, mFrecencyArraySorted(false)
{
sLock.AssertCurrentThreadOwns();
LOG(("CacheIndex::CacheIndex [this=%p]", this));
@ -1187,7 +1193,11 @@ CacheIndex::GetEntryForEviction(bool aIgnoreEmptyEntries, SHA1Sum::Hash *aHash,
uint32_t i;
// find first non-forced valid and unpinned entry with the lowest frecency
index->mFrecencyArray.Sort(FrecencyComparator());
if (!index->mFrecencyArraySorted) {
index->mFrecencyArray.Sort(FrecencyComparator());
index->mFrecencyArraySorted = true;
}
for (i = 0; i < index->mFrecencyArray.Length(); ++i) {
memcpy(&hash, &index->mFrecencyArray[i]->mHash, sizeof(SHA1Sum::Hash));
@ -1385,7 +1395,11 @@ CacheIndex::GetIterator(nsILoadContextInfo *aInfo, bool aAddNew,
iter = new CacheIndexIterator(index, aAddNew);
}
index->mFrecencyArray.Sort(FrecencyComparator());
if (!index->mFrecencyArraySorted) {
index->mFrecencyArray.Sort(FrecencyComparator());
index->mFrecencyArraySorted = true;
}
iter->AddRecords(index->mFrecencyArray);
index->mIterators.AppendElement(iter);
@ -3161,6 +3175,7 @@ CacheIndex::InsertRecordToFrecencyArray(CacheIndexRecord *aRecord)
MOZ_ASSERT(!mFrecencyArray.Contains(aRecord));
mFrecencyArray.AppendElement(aRecord);
mFrecencyArraySorted = false;
}
void

View File

@ -1020,6 +1020,7 @@ private:
// and such entries are stored at the end of the array. Uninitialized entries
// and entries marked as deleted are not present in this array.
nsTArray<CacheIndexRecord *> mFrecencyArray;
bool mFrecencyArraySorted;
nsTArray<CacheIndexIterator *> mIterators;

View File

@ -1239,6 +1239,16 @@ CacheStorageService::PurgeOverMemoryLimit()
LOG(("CacheStorageService::PurgeOverMemoryLimit"));
static TimeDuration const kFourSeconds = TimeDuration::FromSeconds(4);
TimeStamp now = TimeStamp::NowLoRes();
if (!mLastPurgeTime.IsNull() && now - mLastPurgeTime < kFourSeconds) {
LOG((" bypassed, too soon"));
return;
}
mLastPurgeTime = now;
Pool(true).PurgeOverMemoryLimit();
Pool(false).PurgeOverMemoryLimit();
}

View File

@ -311,7 +311,7 @@ private:
nsTArray<RefPtr<CacheEntry> > mFrecencyArray;
nsTArray<RefPtr<CacheEntry> > mExpirationArray;
mozilla::Atomic<uint32_t> mMemorySize;
Atomic<uint32_t, Relaxed> mMemorySize;
bool OnMemoryConsumptionChange(uint32_t aSavedMemorySize,
uint32_t aCurrentMemoryConsumption);
@ -330,6 +330,7 @@ private:
MemoryPool mDiskPool;
MemoryPool mMemoryPool;
TimeStamp mLastPurgeTime;
MemoryPool& Pool(bool aUsingDisk)
{
return aUsingDisk ? mDiskPool : mMemoryPool;