From 49926bb9ef983d4c19aed635a00b388252c065e4 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 20 Jul 2016 10:29:51 +0200 Subject: Fix performance regression when changing fonts Change e109b8a0f3c89c595f0da689e7ee847130e2ee47 introduced a performance regression when rapidly switching fonts as long as the number of different fonts is over a relatively small number, since the cost of fonts can be high compared to the limits set on the cache. Since the original patch was intended to avoid exceeding the open file limit when using Freetype on Windows, we add an additional check on the number of engines in the cache as well for the added, synchronous cache flush. The limit is set to 256 to make it unlikely that it is exceeded during a single paint event, but it can also be configured when building Qt if a higher limit is needed. [ChangeLog][QtGui][Text] Fixed performance regression when rapidly switching between a large set of fonts. Task-number: QTBUG-54180 Change-Id: I92b9fbe14fca4f11c9c6dfdcdbec6d19a61b86a7 Reviewed-by: Konstantin Ritt --- src/gui/text/qfont.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index fe68149346..ea34614cb5 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -70,7 +70,9 @@ QT_BEGIN_NAMESPACE - +#ifndef QFONTCACHE_DECREASE_TRIGGER_LIMIT +# define QFONTCACHE_DECREASE_TRIGGER_LIMIT 256 +#endif bool QFontDef::exactMatch(const QFontDef &other) const { @@ -2797,7 +2799,7 @@ void QFontCache::insertEngineData(const QFontDef &def, QFontEngineData *engineDa engineData->ref.ref(); // Decrease now rather than waiting - if (total_cost > min_cost * 2) + if (total_cost > min_cost * 2 && engineDataCache.size() >= QFONTCACHE_DECREASE_TRIGGER_LIMIT) decreaseCache(); engineDataCache.insert(def, engineData); @@ -2846,7 +2848,7 @@ void QFontCache::insertEngine(const Key &key, QFontEngine *engine, bool insertMu #endif engine->ref.ref(); // Decrease now rather than waiting - if (total_cost > min_cost * 2) + if (total_cost > min_cost * 2 && engineCache.size() >= QFONTCACHE_DECREASE_TRIGGER_LIMIT) decreaseCache(); Engine data(engine); -- cgit v1.2.3