Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-72821

QPainter::setClipRegion slow on HiDPI for complex QRegion

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.12.0
    • Fix Version/s: 5.14.0 Alpha
    • Environment:
      MacPro (Late 2013) macOS 10.13.6 with HiDPI monitor or any Mac with Retina display, HP z840 running Windows 10 with HiDPI monitor set to 200%.
    • Platform/s:
      macOS, Windows
    • Commits:
      64fab8f7e2d225e37aa731db7501b5d5b82eab64 (qt/qtbase/dev)

      Description

      We are seeing major performance issues on HiDPI displays, both Mac and Windows where there are also complex clip regions.

      We have one window that can have thousands of areas with custom painting on a single QWidget. On this window we have some mouse selection operations that subsequently redraw portions of the window after setting a complex clipping region. In this case, "complex" means from 300 to 1000 or more rects. Note that this is still only a subset of the entire window area.

      When the user does these selection operations on HiDPI displays it can sometimes take a couple of seconds to 30 seconds or more, depending upon the number of items selected.

      When we looked for hot spots in Xcode Instruments and Visual Studio 2017 the we are seeing anywhere from 85 to 90% of the time in the 

       

      QPainter::setClipRegion(QRegion const&, Qt::ClipOperation) 
      

      method.

      Here are some timings from a MacPro (Late 2013) (the Windows numbers are about twice as long.) 

      Total Time % CPU Time Method
      3.96 s 85.7% 0 s QPainter::setClipRegion(QRegion const&, Qt::ClipOperation)
      3.96 s 85.7% 0 s QRasterPaintEngine::clip(QRegion const&, Qt::ClipOperation)
      3.96 s 85.7% 1.00 ms QTransform::map(QRegion const&) const
      3.82 s 82.6% 0 s QRegion::QRegion(QPolygon const&, Qt::FillRule)
      3.81 s 82.4% 3.56 s PolygonRegion(QPoint const*, int, int)
      Total Time % CPU Time Method
      11.61 s 90.2% 2.00 ms QPainter::setClipRegion(QRegion const&, Qt::ClipOperation)
      11.61 s 90.2% 2.00 ms QRasterPaintEngine::clip(QRegion const&, Qt::ClipOperation)
      11.61 s 90.2% 1.00 ms QTransform::map(QRegion const&) const
      11.25 s 87.3% 0 s QRegion::QRegion(QPolygon const&, Qt::FillRule)
      11.22 s 87.1% 10.35 s PolygonRegion(QPoint const*, int, int)

      It seems that on HiDPI displays the 2.0 display aspect ratio causes the array of rectangles in the QRegion to be mapped to QPolygonRegion and this mapping operations is very CPU intensive.

      Suggestion: Add an optimization to avoid the mapping to polygon regions if the transform has no rotation or skew. This should create a QRegion with the same number rectangles.

        Attachments

        1. main.cpp
          1 kB
        2. main2.cpp
          2 kB
        3. qtbug72821.zip
          1.0 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            lagocs Laszlo Agocs
            Reporter:
            tom.ransdell Tom Ransdell
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes