Closed letsfindaway closed 3 months ago
Note: There is one BIG problem with asynchronous loading:
All QGraphicsItem
share a global object for storing data. This is a QHash<const QGraphicsItem *, QMap<int, QVariant> > data
which stores the data for all items globally. Access to this hash is not protected against concurrent access from several threads.
As building a scene involves creating many items, where each item uses this map, we cannot safely do this on any other thread than the main application thread. This problem is completely independent of the thread affinity of objects and cannot be solved by the application.
The only possibility I see is to do loading on the main thread, but to cut it into small pieces, which are executed whenever the main thread is idle. Let me say, if the UBSvgSubsetAdaptor
would have a function which reads data for a single item and creates that item, and then returns, we could call this function when the main thread has nothing else to do. Such a programming pattern requires that all context of loading is held in a variable which can be passed to this function. Let's see how big this context is! Best case it is only the XML reader and the scene.
See https://github.com/OpenBoard-org/OpenBoard/pull/941 for my PR to address this issue.
Actually the context needed to load a file in small steps is the UBSvgSubsetReader
if we move three local variables to member variables.
This issue collects several other issues related to scene management, tries to provide a common overview and propose steps for solving. The issues are:
The effects for the user are
Reasons for these issues are
Steps for addressing these issues
The following proposes a step-wise approach to solve these interrelated issues.
UBDraggableLivePixmapItem
so that it can be released from the cache if necessary.UBSceneCache
and add a LRU policy for removing the least recently used scene. This is a requirement for reducing the memory usage on heavy documents with many pages. Note that most parts of this are already there and have been deactivated when scenes have been used for all thumbnails. As we're now using pixmaps again for inactive pages, we can reactivate this.