Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-727

PySide2 QTableWidget setItem Very Slow compare with PyQt5

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.11.1
    • 5.11.0
    • PySide
    • None
    • WIN10 PYCHARM PYTHON3.6 PYQT5 PYSIDE2(5.11)
    • Windows
    • a1b09497f2f198e6ea523637321a0e11fa310d9c (pyside-setup/5.11, 19.7.2018, 5.11.1)

    Description

      I have a data with 1000 records showing in QTableWidget (13 columns), after refresh 4 times, I get setItem 52000 times, and using pycharm Profile method, the time for 52000 times is 84ms. After PySide2 come out ( Qt for Python 5.11 mid May), I only change from "from PyQt5... import ..." to "from PySide2... import ..." for my program, the time for 52000 times is 3171ms. I know both PyQt5 and PySide2 depend on Qt5, but the performance shocked. I want to use PySide2 for future with LGPL, how can I fix it ?

       

      // code placeholder
      #!/usr/bin/env python
      # -*- coding: utf-8 -*-
      import sys
      from PySide2.QtWidgets import QApplication, QTableWidgetItem, QMainWindow, QTableWidget
      
      
      class MainWindow(QMainWindow):
          def __init__(self):
              super().__init__()
              self.setGeometry(200, 300, 960, 540)
              self.table = QTableWidget()
              self.setCentralWidget(self.table)
              self.table.setRowCount(1000)
              self.horizontal_header = ["1", "2", "3", "4", "5", "6", "7",
                                        "8", "9", "10", "11", "12", "13"]
              self.table.setColumnCount(len(self.horizontal_header))
              self.table.setHorizontalHeaderLabels(self.horizontal_header)
              for i in range(4):
                  self._run()
              raise NameError
      
          def _run(self):
              for row in range(1000):
                  for column in range(13):
                      item = QTableWidgetItem('1')
                      self.table.setItem(row, column, item)
      
      
      if __name__ == '__main__':
          app = QApplication(sys.argv)
          mainwindow = MainWindow()
          mainwindow.show()
          sys.exit(app.exec_())
      
      Qt 5.11.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 7.2.0)
      Attempt # 0 / 4
      Populating 1000
      Done 44 ms
      Attempt # 1 / 4
      Populating 1000
      Done 972 ms
      Attempt # 2 / 4
      Populating 1000
      Done 989 ms
      Attempt # 3 / 4
      Populating 1000
      Done 1056 ms
      
      C++ "5.11.1 xcb" ()
      Qt 5.11.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 7.2.0)
      Attempt # 0 / 4
      Populating 1000
      Done 5 ms
      Attempt # 1 / 4
      Populating 1000
      Done 5 ms
      Attempt # 2 / 4
      Populating 1000
      Done 5 ms
      Attempt # 3 / 4
      Populating 1000
      Done 5 ms
      

      Attachments

        1. 1_plot.png
          1_plot.png
          28 kB
        2. 4_plot.png
          4_plot.png
          31 kB
        3. plot_comparison.png
          plot_comparison.png
          27 kB
        4. plot_improvement.png
          plot_improvement.png
          33 kB
        5. plot_map_1time.png
          plot_map_1time.png
          38 kB
        6. plot_map_4times.png
          plot_map_4times.png
          39 kB
        7. plot_nodebug_1time.png
          plot_nodebug_1time.png
          35 kB
        8. plot_nodebug_4times.png
          plot_nodebug_4times.png
          39 kB
        9. plot_repeated_4times.png
          plot_repeated_4times.png
          30 kB
        10. plot_vector_single.png
          plot_vector_single.png
          36 kB
        11. plot_vector.png
          plot_vector.png
          40 kB
        12. pyside727_cpp.zip
          2 kB
        13. pyside727.py
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            dearfad dearfad
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews