From cf695cade4ca717147461d6842ced522f5f3b8e9 Mon Sep 17 00:00:00 2001 From: cxl Date: Sat, 13 Jun 2020 17:13:27 +0000 Subject: [PATCH] CtrlCore: Fixed performance issue with Font cache in Gtk3 backend git-svn-id: svn://ultimatepp.org/upp/trunk@14590 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Other.h | 1 + uppsrc/Core/Speller.cpp | 2 +- uppsrc/Core/ValueCache.cpp | 2 +- uppsrc/Core/src.tpp/LRUCache_en-us.tpp | 11 +++++++++-- uppsrc/CtrlCore/GtkDrawText.cpp | 2 +- uppsrc/CtrlLib/LineEdit.cpp | 2 +- uppsrc/ide/Designers/HexView.cpp | 2 +- 7 files changed, 15 insertions(+), 7 deletions(-) diff --git a/uppsrc/Core/Other.h b/uppsrc/Core/Other.h index eba9d8a33..08f19af4b 100644 --- a/uppsrc/Core/Other.h +++ b/uppsrc/Core/Other.h @@ -381,6 +381,7 @@ public: const K& GetLRUKey(); void DropLRU(); void Shrink(int maxsize, int maxcount = 30000); + void ShrinkCount(int maxcount = 30000) { Shrink(INT_MAX, maxcount); } template int Remove(P predicate); template bool RemoveOne(P predicate); diff --git a/uppsrc/Core/Speller.cpp b/uppsrc/Core/Speller.cpp index 210f607fe..09d8a58c5 100644 --- a/uppsrc/Core/Speller.cpp +++ b/uppsrc/Core/Speller.cpp @@ -294,7 +294,7 @@ static LRUCache speller_cache; bool SpellWord(const WString& ws, int lang) { - speller_cache.Shrink(2000); + speller_cache.ShrinkCount(2000); SpellMaker m; m.k.lang = lang; m.k.wrd = ws; diff --git a/uppsrc/Core/ValueCache.cpp b/uppsrc/Core/ValueCache.cpp index 619e84044..ab3c88962 100644 --- a/uppsrc/Core/ValueCache.cpp +++ b/uppsrc/Core/ValueCache.cpp @@ -47,7 +47,7 @@ void ShrinkValueCache() Mutex::Lock __(ValueCacheMutex); if(!ValueCacheMaxSizeLimitHigh) AdjustValueCache(); - TheValueCache().Shrink(ValueCacheMaxSize, 2000); + TheValueCache().Shrink(ValueCacheMaxSize, 20000); LLOG("MakeValue cache size after shrink: " << TheValueCache().GetSize()); } diff --git a/uppsrc/Core/src.tpp/LRUCache_en-us.tpp b/uppsrc/Core/src.tpp/LRUCache_en-us.tpp index c6930b00f..303bdf53a 100644 --- a/uppsrc/Core/src.tpp/LRUCache_en-us.tpp +++ b/uppsrc/Core/src.tpp/LRUCache_en-us.tpp @@ -45,7 +45,7 @@ nst]_`=_[@3 0]&] [s5;:LRUCache`:`:Maker`:`:Make`(T`&`)const: [@(0.0.255) virtual] [@(0.0.255) int]_[* Make]( [*@4 T][@(0.0.255) `&]_[*@3 object])_[@(0.0.255) const]_`=_[@3 0]&] [s2;%% Creates the data based on parameters, returns the size of -created data.&] +created data in bytes.&] [s3;%% &] [s4; &] [s5;:LRUCache`:`:Maker`:`:`~Maker`(`): [@(0.0.255) `~][* Maker]()&] @@ -56,7 +56,8 @@ created data.&] [s3; &] [s5;:LRUCache`:`:GetSize`(`)const: [@(0.0.255) int]_[* GetSize]()_[@(0.0.255) const]&] [s2;%% Returns the total size of data in cache (as sum of numbers -returned by Maker`::Make).&] +returned by Maker`::Make). Note that LRUCache adds and estimate +of its internal memory consumption per item as well.&] [s3;%% &] [s4; &] [s5;:LRUCache`:`:GetCount`(`)const: [@(0.0.255) int]_[* GetCount]()_[@(0.0.255) const]&] @@ -94,6 +95,12 @@ and [%-*@3 maxcount] items removing the least recently used items first.&] [s3;%% &] [s4; &] +[s5;:Upp`:`:LRUCache`:`:ShrinkCount`(int`): [@(0.0.255) void]_[* ShrinkCount]([@(0.0.255) i +nt]_[*@3 maxcount]_`=_[@3 30000])&] +[s2;%% Reduces the cache to contain no more than [%-*@3 maxcount] regardless +of data size.&] +[s3;%% &] +[s4; &] [s5;:LRUCache`:`:Remove`(P`): [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 P]>_[@(0.0.255) i nt]_[* Remove]([*@4 P]_[*@3 predicate])&] [s2;%% Removes data items from the cache for which [%-*@3 predicate] diff --git a/uppsrc/CtrlCore/GtkDrawText.cpp b/uppsrc/CtrlCore/GtkDrawText.cpp index bd52469f2..948bc0286 100644 --- a/uppsrc/CtrlCore/GtkDrawText.cpp +++ b/uppsrc/CtrlCore/GtkDrawText.cpp @@ -85,7 +85,7 @@ void SystemDraw::FlushText() SetColor(textink); cairo_show_glyphs(cr, gs, textcache.GetCount()); - cache.Shrink(64); + cache.Shrink(INT_MAX, 128); textcache.Clear(); } diff --git a/uppsrc/CtrlLib/LineEdit.cpp b/uppsrc/CtrlLib/LineEdit.cpp index a96bc1a8c..f94d7ebc4 100644 --- a/uppsrc/CtrlLib/LineEdit.cpp +++ b/uppsrc/CtrlLib/LineEdit.cpp @@ -3,7 +3,7 @@ namespace Upp { #define LLOG(x) // LOG(x) -#define LTIMING(x) // RTIMING(x) +#define LTIMING(x) // DTIMING(x) LineEdit::LineEdit() { isdrag = false; diff --git a/uppsrc/ide/Designers/HexView.cpp b/uppsrc/ide/Designers/HexView.cpp index b8ef7d6cc..712779013 100644 --- a/uppsrc/ide/Designers/HexView.cpp +++ b/uppsrc/ide/Designers/HexView.cpp @@ -69,7 +69,7 @@ int FileHexView::Byte(int64 addr) { blk = addr >> BLKSHIFT; String h = cache.Get(*this); - cache.Shrink(10); // cache only 10 blocks (~150 KB) + cache.ShrinkCount(10); // cache only 10 blocks (~150 KB) int ii = addr & (BLKSIZE - 1); return ii < h.GetCount() ? (byte)h[ii] : 0; }