kit/Kit.cpp | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-)
New commits: commit fcafa15d5b7de74692f4e0046db8b20b8918cd28 Author: Michael Meeks <[email protected]> AuthorDate: Fri May 3 13:20:14 2019 +0100 Commit: Andras Timar <[email protected]> CommitDate: Fri May 3 14:37:37 2019 +0200 Fix strange wire-id hash issues. Remove un-used hash; and ensure that the hash <-> wid mapping is suitably unique and helpful, even for duplicate identical tiles in a single tilecombine. Change-Id: I9c752032231e164765615a7c0d6338d6ff7e3fd5 Reviewed-on: https://gerrit.libreoffice.org/71740 Reviewed-by: Andras Timar <[email protected]> Tested-by: Andras Timar <[email protected]> diff --git a/kit/Kit.cpp b/kit/Kit.cpp index 228af098e..05dbdc722 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -433,13 +433,15 @@ class PngCache size_t _cacheSize; static const size_t CacheSizeSoftLimit = (1024 * 4 * 32); // 128k of cache static const size_t CacheSizeHardLimit = CacheSizeSoftLimit * 2; + static const size_t CacheWidHardLimit = 4096; size_t _cacheHits; size_t _cacheTests; TileWireId _nextId; DeltaGenerator _deltaGen; - std::map< TileBinaryHash, CacheEntry > _cache; - std::map< TileWireId, TileBinaryHash > _wireToHash; + std::unordered_map< TileBinaryHash, CacheEntry > _cache; + // This uses little storage so can be much larger + std::unordered_map< TileBinaryHash, TileWireId > _hashToWireId; void clearCache(bool logStats = false) { @@ -447,6 +449,7 @@ class PngCache LOG_DBG("cache clear " << _cache.size() << " items total size " << _cacheSize << " current hits " << _cacheHits); _cache.clear(); + _hashToWireId.clear(); _cacheSize = 0; _cacheHits = 0; _cacheTests = 0; @@ -486,11 +489,6 @@ class PngCache // Shrink cache when we exceed the size to maximize // the chance of hitting these entries in the future. _cacheSize -= it->second.getData()->size(); - - auto wIt = _wireToHash.find(it->second.getWireId()); - assert(wIt != _wireToHash.end()); - _wireToHash.erase(wIt); - it = _cache.erase(it); } else @@ -504,6 +502,20 @@ class PngCache LOG_DBG("cache " << _cache.size() << " items total size " << _cacheSize << " after balance"); } + + if (_hashToWireId.size() > CacheWidHardLimit) + { + LOG_DBG("Clear half of wid cache of size " << _hashToWireId.size()); + TileWireId max = _nextId - CacheWidHardLimit/2; + for (auto it = _hashToWireId.begin(); it != _hashToWireId.end();) + { + if (it->second < max) + it = _hashToWireId.erase(it); + else + ++it; + } + LOG_DBG("Wid cache is now size " << _hashToWireId.size()); + } } /// Lookup an entry in the cache and store the data in output. @@ -574,18 +586,18 @@ public: clearCache(); } - TileWireId hashToWireId(TileBinaryHash id) + TileWireId hashToWireId(TileBinaryHash hash) { TileWireId wid; - if (id == 0) + if (hash == 0) return 0; - auto it = _cache.find(id); - if (it != _cache.end()) - wid = it->second.getWireId(); + auto it = _hashToWireId.find(hash); + if (it != _hashToWireId.end()) + wid = it->second; else { wid = createNewWireId(); - _wireToHash.emplace(wid, id); + _hashToWireId.emplace(hash, wid); } return wid; } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
