Feature request #2037
Enable multi-threaded rendering in QGIS
|Pull Request or Patch supplied:||No||Resolution:|
|Easy fix?:||No||Copied to github as #:||12097|
User story 1: Joe has a multicore processor but when QGIS is rendering a map, one of the cores is heavily utilised whilst the rest remain idle.
User story 2: Pam wishes she didnt need to wait so long for maps to draw as each layer draw carries out a long running query against a database backend.
Qt4 includes QThread which makes writing multithreaded cross platform libraries fairly easily. Thus it would be good to start thinking about how we can make QGIS take advantage of this.
In my mind there are two main areas of work required:
- making map layers inherit from QThread and adding in sufficient foundation for them to be able to render in a thread (pretty much covered in the attached patch).
- Updating qgsmaprenderer.cpp to orchestrate the threaded rendering of map layers and the composition of the results.
For the second (renderer part) we will need to split the render process into three parts I think:
- a setup phase which sets the render context for each maplayer (which would need to become a member of qgsmaplayer) and then calls the run() method to launch the thread
- a slot to listen for when each thread is done and tally up when all the rendering work is completed
- a finalise method to end the render process with label and acetate rendering and perform final compositing from layer render cache images.
#1 Updated by Marco Hugentobler about 10 years ago
Please also consider the QtConcurrent (http://doc.trolltech.com/4.5/threads.html#qtconcurrent) framework as an option. The advantage over inheritance from QThread is that the number of created threads automatically adapts depending on the number of cores. Furthermore it is more high-level and therefore simpler to use. And it does not require api changes in QgsMapLayer.