From: Eunki, Hong Date: Mon, 13 Jun 2022 13:08:02 +0000 (+0900) Subject: Heuristic optimize on GetFontId X-Git-Tag: dali_2.1.27~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F58%2F276258%2F3;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git Heuristic optimize on GetFontId Most of case, we use same font and size continously. So before find container, We can re-use latest comparision. GetFontId called for every characters. So, minor reducing will help to whole runtime. Change-Id: I291655c709b9bafa62c7d4f6b669eff589b1766e Signed-off-by: Eunki, Hong --- diff --git a/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp b/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp index 1c63e32..e7589a1 100644 --- a/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp +++ b/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp @@ -272,6 +272,8 @@ FontClient::Plugin::Plugin(unsigned int horizontalDpi, mVectorFontCache(nullptr), mEllipsisCache(), mEmbeddedItemCache(), + mLatestFoundFontDescription(), + mLatestFoundCacheKey(0, 0), mDefaultFontDescriptionCached(false), mIsAtlasLimitationEnabled(TextAbstraction::FontClient::DEFAULT_ATLAS_LIMITATION_ENABLED), mCurrentMaximumBlockSizeFitInAtlas(TextAbstraction::FontClient::MAX_SIZE_FIT_IN_ATLAS) @@ -338,6 +340,9 @@ void FontClient::Plugin::ClearCache() mEmbeddedItemCache.Clear(); mBitmapFontCache.clear(); + mLatestFoundFontDescription.family.clear(); + mLatestFoundCacheKey = FontDescriptionSizeCacheKey(0, 0); + mDefaultFontDescriptionCached = false; } @@ -1770,16 +1775,37 @@ bool FontClient::Plugin::FindValidatedFont(const FontDescription& fontDescriptio fontDescriptionId = 0u; + // Fast cut if inputed family is empty. + if(DALI_UNLIKELY(fontDescription.family.empty())) + { + DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " validated font description not found / fontDescription.family is empty!\n"); + return false; + } + + // Heuristic optimize code : Compare with latest found item. + if((fontDescription.width == mLatestFoundFontDescription.width) && + (fontDescription.weight == mLatestFoundFontDescription.weight) && + (fontDescription.slant == mLatestFoundFontDescription.slant) && + (fontDescription.family == mLatestFoundFontDescription.family)) + { + fontDescriptionId = mLatestFoundFontDescriptionId; + + DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " validated font description same as latest, id : %d\n", fontDescriptionId); + return true; + } + for(const auto& item : mValidatedFontCache) { - if(!fontDescription.family.empty() && - (fontDescription.family == item.fontDescription.family) && - (fontDescription.width == item.fontDescription.width) && + if((fontDescription.width == item.fontDescription.width) && (fontDescription.weight == item.fontDescription.weight) && - (fontDescription.slant == item.fontDescription.slant)) + (fontDescription.slant == item.fontDescription.slant) && + (fontDescription.family == item.fontDescription.family)) { fontDescriptionId = item.index; + mLatestFoundFontDescription = fontDescription; + mLatestFoundFontDescriptionId = fontDescriptionId; + DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " validated font description found, id : %d\n", fontDescriptionId); return true; } @@ -1829,13 +1855,25 @@ bool FontClient::Plugin::FindFont(FontDescriptionId fontDescriptionId, fontCacheIndex = 0u; - FontDescriptionSizeCacheKey key(fontDescriptionId, requestedPointSize); + const FontDescriptionSizeCacheKey key(fontDescriptionId, requestedPointSize); + + // Heuristic optimize code : Compare with latest found item. + if(key == mLatestFoundCacheKey) + { + fontCacheIndex = mLatestFoundCacheIndex; + + DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font same as latest, index of font cache : %d\n", fontCacheIndex); + return true; + } const auto& iter = mFontDescriptionSizeCache.find(key); if(iter != mFontDescriptionSizeCache.cend()) { fontCacheIndex = iter->second; + mLatestFoundCacheKey = key; + mLatestFoundCacheIndex = fontCacheIndex; + DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font found, index of font cache : %d\n", fontCacheIndex); return true; } diff --git a/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.h b/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.h index b73ae6d..bef0f89 100644 --- a/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.h +++ b/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.h @@ -620,6 +620,12 @@ private: Vector mEmbeddedItemCache; ///< Cache embedded items. std::vector mBitmapFontCache; ///< Stores bitmap fonts. + FontDescription mLatestFoundFontDescription; ///< Latest found font description and id in FindValidatedFont() + FontDescriptionId mLatestFoundFontDescriptionId; + + FontDescriptionSizeCacheKey mLatestFoundCacheKey; ///< Latest found font description and id in FindFont() + FontCacheIndex mLatestFoundCacheIndex; + bool mDefaultFontDescriptionCached : 1; ///< Whether the default font is cached or not bool mIsAtlasLimitationEnabled : 1; ///< Whether the validation on maximum atlas block size, then reduce block size to fit into it is enabled or not.