From c6cf2320d2a464594e759289c34796538d31f02b Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 27 Apr 2018 18:30:45 +0900 Subject: config entries for the new graphic manager, deprecate old entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add 2 new GraphicManager config entries GraphicMemoryLimit and GraphicAllowedIdleTime. At the same time, deprecate the existing config entries used in GraphicObject's GraphicManager, which are not relevant anymore. Change-Id: Idb775e5e1a623f6c23d0c67fea5334a6c713c6c2 Reviewed-on: https://gerrit.libreoffice.org/53561 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- .../schema/org/openoffice/Office/Common.xcs | 21 +++++++++++++++++++++ vcl/inc/graphic/Manager.hxx | 3 ++- vcl/source/graphic/Manager.cxx | 22 ++++++++++++++-------- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs index 390b54595e40..88b6f3b07f1b 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs @@ -1491,6 +1491,7 @@ + Not used anymore Specifies the maximum cache size for all graphical display objects. @@ -1499,6 +1500,7 @@ + Not used anymore Specifies the maximum cache size for a single graphic display object. @@ -1507,12 +1509,31 @@ + Not used anymore Specifies the time in seconds after which a cached object is freed from the cache. 600 + + + Specifies the allowed cumulated memory that the + graphic objects can occupy before they start to get swapped + to the disk to save memory. + + + 300000000 + + + + Specifies the time in seconds when the graphic object + can be idle (time since it was last used) before it is + considered to be swapped to the disk to save memory. + + + 10 + diff --git a/vcl/inc/graphic/Manager.hxx b/vcl/inc/graphic/Manager.hxx index 6dd88a5a4c1c..88d57229f9e2 100644 --- a/vcl/inc/graphic/Manager.hxx +++ b/vcl/inc/graphic/Manager.hxx @@ -36,7 +36,8 @@ class Manager final { private: std::unordered_set m_pImpGraphicList; - sal_Int64 mnTotalCacheSize; + std::chrono::seconds mnAllowedIdleTime; + sal_Int64 mnMemoryLimit; sal_Int64 mnUsedSize; Timer maSwapOutTimer; diff --git a/vcl/source/graphic/Manager.cxx b/vcl/source/graphic/Manager.cxx index 106677cc0db4..c2146a680e8a 100644 --- a/vcl/source/graphic/Manager.cxx +++ b/vcl/source/graphic/Manager.cxx @@ -30,14 +30,19 @@ namespace graphic { namespace { -void setTotalCacheSizeFromConfigIfPossible(sal_Int64& nTotalCacheSize) +void setupConfigurationValuesIfPossible(sal_Int64& rMemoryLimit, + std::chrono::seconds& rAllowedIdleTime) { if (utl::ConfigManager::IsFuzzing()) return; try { - nTotalCacheSize = officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::get(); + using officecfg::Office::Common::Cache; + + rMemoryLimit = Cache::GraphicManager::GraphicMemoryLimit::get(); + rAllowedIdleTime + = std::chrono::seconds(Cache::GraphicManager::GraphicAllowedIdleTime::get()); } catch (...) { @@ -52,11 +57,12 @@ Manager& Manager::get() } Manager::Manager() - : mnTotalCacheSize(50000000) + : mnAllowedIdleTime(10) + , mnMemoryLimit(300000000) , mnUsedSize(0) , maSwapOutTimer("graphic::Manager maSwapOutTimer") { - setTotalCacheSizeFromConfigIfPossible(mnTotalCacheSize); + setupConfigurationValuesIfPossible(mnMemoryLimit, mnAllowedIdleTime); maSwapOutTimer.SetInvokeHandler(LINK(this, Manager, SwapOutTimerHandler)); maSwapOutTimer.SetTimeout(10000); @@ -68,7 +74,7 @@ void Manager::reduceGraphicMemory() { for (ImpGraphic* pEachImpGraphic : m_pImpGraphicList) { - if (mnUsedSize < mnTotalCacheSize * 0.7) + if (mnUsedSize < mnMemoryLimit * 0.7) return; sal_Int64 nCurrentGraphicSize = getGraphicSizeBytes(pEachImpGraphic); @@ -79,8 +85,8 @@ void Manager::reduceGraphicMemory() auto aCurrent = std::chrono::high_resolution_clock::now(); auto aDeltaTime = aCurrent - pEachImpGraphic->maLastUsed; auto aSeconds = std::chrono::duration_cast(aDeltaTime); - double nSeconds = aSeconds.count(); - if (nSeconds > 10) + + if (aSeconds > mnAllowedIdleTime) pEachImpGraphic->ImplSwapOut(); } } @@ -105,7 +111,7 @@ void Manager::registerGraphic(std::shared_ptr& pImpGraphic, OUString const& /*rsContext*/) { // make some space first - if (mnUsedSize > mnTotalCacheSize) + if (mnUsedSize > mnMemoryLimit) reduceGraphicMemory(); // Insert and update the used size (bytes) -- cgit v1.2.3