From 0be811c519795607fea0b79e3dd2b01e487d65bb Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 03:42:21 +0100 Subject: [PATCH] Update the resource cache every second instead of every frame A dry run takes about ~1.5ms. Even though it's all done in the worker thread, the locks used can stall loading operations that are about to happen in other threads, and just in general this CPU load is unnecessary. --- apps/openmw/mwworld/cellpreloader.cpp | 9 +++++++-- apps/openmw/mwworld/cellpreloader.hpp | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/cellpreloader.cpp b/apps/openmw/mwworld/cellpreloader.cpp index 9f613ac80..7524fefd8 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -179,6 +179,7 @@ namespace MWWorld , mMinCacheSize(0) , mMaxCacheSize(0) , mPreloadInstances(true) + , mLastResourceCacheUpdate(0.0) { } @@ -252,8 +253,12 @@ namespace MWWorld ++it; } - // the resource cache is cleared from the worker thread so that we're not holding up the main thread with delete operations - mWorkQueue->addWorkItem(new UpdateCacheItem(mResourceSystem, mTerrain, timestamp), true); + if (timestamp - mLastResourceCacheUpdate > 1.0) + { + // the resource cache is cleared from the worker thread so that we're not holding up the main thread with delete operations + mWorkQueue->addWorkItem(new UpdateCacheItem(mResourceSystem, mTerrain, timestamp), true); + mLastResourceCacheUpdate = timestamp; + } } void CellPreloader::setExpiryDelay(double expiryDelay) diff --git a/apps/openmw/mwworld/cellpreloader.hpp b/apps/openmw/mwworld/cellpreloader.hpp index 35c52baf6..e45f92735 100644 --- a/apps/openmw/mwworld/cellpreloader.hpp +++ b/apps/openmw/mwworld/cellpreloader.hpp @@ -61,6 +61,8 @@ namespace MWWorld unsigned int mMaxCacheSize; bool mPreloadInstances; + double mLastResourceCacheUpdate; + struct PreloadEntry { PreloadEntry(double timestamp, osg::ref_ptr workItem)