Fix performance regression when changing fonts

Change e109b8a0f3 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 <ritt.ks@gmail.com>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2016-07-20 10:29:51 +02:00
parent 77a71c32c9
commit 49926bb9ef

View File

@ -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);