From 5da83e670d18c46e31f1672801d1feb4079ec60f Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 8 Feb 2026 08:43:03 +0100 Subject: [PATCH] Restoring drawing performance --- src/db/db/dbLayout.cc | 28 +++++++++++++--------------- src/tl/tl/tlThreads.h | 6 ++---- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/db/db/dbLayout.cc b/src/db/db/dbLayout.cc index 004e52d3d..dacfcbd4f 100644 --- a/src/db/db/dbLayout.cc +++ b/src/db/db/dbLayout.cc @@ -1779,13 +1779,6 @@ Layout::end_changes_no_update () void Layout::force_update () { - // NOTE: the assumption is that either one thread is writing or - // multiple threads are reading. Hence, we do not need to lock hier_dirty() or bboxes_dirty(). - // We still do double checking as another thread might do the update as well. - if (! update_needed ()) { - return; - } - tl::MutexLocker locker (&lock ()); force_update_no_lock (); } @@ -1817,18 +1810,23 @@ Layout::force_update_no_lock () const void Layout::update () const { - tl::MutexLocker locker (&lock ()); - - // NOTE: the assumption is that either one thread is writing or - // multiple threads are reading. Hence, we do not need to lock hier_dirty() or bboxes_dirty(). - // We still do double checking as another thread might do the update as well. - if (under_construction () || (! hier_dirty () && ! bboxes_dirty () && ! prop_ids_dirty ())) { + // NOTE: this is double checking - which is not inherently thread-safe. + // However, it's so much faster, and the deal is to start multithreaded + // reads with an already-updated layout and not to do reading from one thread + // while writing from another. So it's worth the risk. + if (! (hier_dirty () || bboxes_dirty () || prop_ids_dirty ())) { return; } - if (! under_construction ()) { - force_update_no_lock (); + tl::MutexLocker locker (&lock ()); + + // We do double checking here as another thread might do the update as well. + // Checking "under_constrcution" will also prevent recursion in "update". + if (under_construction () || ! (hier_dirty () || bboxes_dirty () || prop_ids_dirty ())) { + return; } + + force_update_no_lock (); } bool diff --git a/src/tl/tl/tlThreads.h b/src/tl/tl/tlThreads.h index 6dd5e4e8a..28155f863 100644 --- a/src/tl/tl/tlThreads.h +++ b/src/tl/tl/tlThreads.h @@ -57,13 +57,12 @@ public: #else -// The non-Qt version is a dummy implementation as threading is not supported (yet) class TL_PUBLIC Mutex { public: Mutex () : m_spinlock () { } - void lock() { m_spinlock.lock(); } - void unlock() { m_spinlock.unlock(); } + void lock () { m_spinlock.lock (); } + void unlock () { m_spinlock.unlock (); } private: atomic::spinlock m_spinlock; }; @@ -91,7 +90,6 @@ public: class WaitConditionPrivate; -// The non-Qt version is a dummy implementation as threading is not supported (yet) class TL_PUBLIC WaitCondition { public: