Results 1 to 19 of 19

Thread: QTableView performances

  1. #1
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QTableView performances

    Hi,

    I am using a QTableView to display a table containing 3949 lines and 12 columns.

    It's very long (>1 min).

    I am using my own model named SKGObjectModel (derived from SKGObjectModelBase (derived from QAbstractItemModel)).

    Here is a part of my analysis:
    Qt Code:
    1. ##methode nb call time in this method average %
    2. ##SKGObjectModel::data 2682080 32612,7 0,01 38,43%
    3. ##SKGObjectModelBase::rowCount 2683753 12215,9 0 14,39%
    4. ##SKGObjectModelBase::index 2683717 11362,9 0 13,39%
    5. ##QAbstractItemModel::reset 11 10761 978,27 12,68%
    6. ##SKGObjectModelBase::data 2323211 9616,11 0 11,33%
    7. ##SKGObjectModelBase::headerData 244223 3669,73 0,02 4,32%
    8. ##SKGServices::executeSelectSqliteOrder(QSqlDatabase) 114 1544,71 13,55 1,82%
    9. ##SKGServices::executeSqliteOrder(QSqlDatabase) 287 1207,02 4,21 1,42%
    10. ##SKGMainPanel::SKGMainPanel 1 559,59 559,59 0,66%
    11. ##SKGMainPanel::setNewTabContent 1 429,53 429,53 0,51%
    12. ##SKGObjectBase::getObjects 37 383,36 10,36 0,45%
    To copy to clipboard, switch view to plain text mode 

    As you can see, data rowCount and index are very performant (average ~ 0) but I have bad performances because of these methods are called to many times (~ 2 600 000 times).

    Do you know why ?
    What can I do to avoid this ?

    In advance, thank you for your help.

    PS: the code is there: http://skrooge.svn.sourceforge.net/viewvc/skrooge/

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView performances

    Don't call reset - you'll reduce the number of calls 11 times Also, what does ::data() implementation look like?

  3. #3
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView performances

    Hi and thank you for your answer,

    In fact reset is called only 3 times for this table:
    1-when the table is initialized and empty
    2-when the table is refreshed to display only 20 lines
    3-when the table is refreshed to display all lines (this is the case with bad performances.

    All other calls are for other tables containing around 10 lines.

    So, I can't reduce the number of call to reset.

    Here is the code:
    Qt Code:
    1. QVariant SKGObjectModelBase::data(const QModelIndex &index, int role) const
    2. {
    3. if (!index.isValid()) return QVariant();
    4. _SKGTRACEIN(10, "SKGObjectModelBase::data");
    5.  
    6. SKGObjectBase* obj = (SKGObjectBase*) index.internalPointer();
    7.  
    8. switch ( role ) {
    9. case Qt::DisplayRole:
    10. case Qt::EditRole:
    11. case Qt::UserRole: {
    12. QString att=listAttibutes[index.column()];
    13. QString val=obj->getAttribute(att);
    14.  
    15. if (att.startsWith("f_")) {
    16. double dval=SKGServices::stringToDouble(val);
    17. return dval;
    18. } else if (att.startsWith("i_")) {
    19. return SKGServices::stringToInt(val);
    20. } else if (att.startsWith("d_")) {
    21. QDate dval=SKGServices::stringToTime(val).date();
    22. if (role == Qt::DisplayRole) {
    23. return KGlobal::locale()->formatDate (dval, KLocale::FancyShortDate);
    24. } else {
    25. return dval;
    26. }
    27. } else if (getRealTable()=="doctransaction" && att=="t_savestep") return "";
    28. return val;
    29. }
    30.  
    31. case Qt::TextColorRole: {
    32. //Text color
    33. QString att=listAttibutes[index.column()];
    34. if (att.startsWith("f_")) {
    35. QVariant value_displayed = SKGObjectModelBase::data(index, Qt::UserRole);
    36. bool ok=false;
    37. double value_double=value_displayed.toDouble(&ok);
    38. if (ok && value_double<0) return qVariantFromValue(QColor(Qt::red));
    39. }
    40. break;
    41. }
    42. case Qt::TextAlignmentRole: {
    43. //Text alignment
    44. QString att=listAttibutes[index.column()];
    45. return (int)(Qt::AlignVCenter|(att.startsWith("f_") || att.startsWith("i_") ? Qt::AlignRight : Qt::AlignLeft));
    46. }
    47. case Qt::DecorationRole: {
    48. //Decoration
    49. if (index.column() == 0 && getRealTable()=="node") {
    50. SKGNodeObject node =*obj;
    51. QStringList data=SKGServices::splitCSVLine(node.getData());
    52. if (data.count()>2) return qVariantFromValue((QIcon) KIcon(data.at(2)));
    53. else {
    54. return qVariantFromValue((QIcon) KIcon(node.getName()==i18n("autostart") ? "folder-bookmarks" : "folder"));
    55. }
    56. } else if (index.column() == 0 && getRealTable()=="doctransaction") {
    57. return qVariantFromValue((QIcon) KIcon(obj->getAttribute("t_mode")=="U" ? "edit-undo" :"edit-redo"));
    58. } else if (getRealTable()=="doctransaction" && listAttibutes[index.column()]=="t_savestep") {
    59. if (obj->getAttribute("t_savestep")=="Y") return qVariantFromValue((QIcon) KIcon("document-save"));
    60. }
    61. break;
    62. }
    63. case Qt::ToolTipRole: {
    64. //Tooltip
    65. if (getRealTable()=="doctransaction") {
    66. document->getMessages(obj->getID(), msg);
    67. int nbMessages=msg.count();
    68. if (nbMessages) {
    69. QString message;
    70. for (int i=0; i<nbMessages; ++i) {
    71. if (i!=0) message+='\n';
    72. message+=msg.at(i);
    73. }
    74.  
    75. return message;
    76. }
    77. }
    78. break;
    79. }
    80. default : {
    81. }
    82. }
    83.  
    84. return QVariant();
    85. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView performances

    Here is the code for SKGObjectModel::data:
    Qt Code:
    1. QVariant SKGObjectModel::data(const QModelIndex &index, int role) const
    2. {
    3. if (!index.isValid()) return QVariant();
    4. _SKGTRACEIN(10, "SKGObjectModel::data");
    5.  
    6. SKGObjectBase* obj = (SKGObjectBase*) index.internalPointer();
    7. switch ( role ) {
    8. case Qt::DisplayRole:
    9. case Qt::EditRole:
    10. case Qt::UserRole: {
    11. QString att=listAttibutes[index.column()];
    12. QString val=obj->getAttribute(att);
    13. if (((getRealTable()=="operation" || getRealTable()=="recurrentoperation") &&
    14. (att=="t_bookmarked" || att=="t_status")) ||
    15. (getRealTable()=="account" && att=="t_close")) {
    16. if (role==Qt::UserRole) return val;
    17. else return "";
    18. } else if (getRealTable()=="account" && att=="t_type") {
    19. if (val=="C") return i18n("Current");
    20. else if (val=="D") return i18n("Credit card");
    21. else if (val=="A") return i18n("Actif");
    22. else if (val=="I") return i18n("Investment");
    23. else return i18n("Other");
    24. } else if (getRealTable()=="unit" && att=="t_type") {
    25. if (val=="1") return i18n("Primary currency");
    26. else if (val=="2") return i18n("Secondary currency");
    27. else if (val=="C") return i18n("Currency");
    28. else if (val=="S") return i18n("Stock");
    29. else return i18n("Object");
    30. } else if (att.startsWith("f_")) {
    31. double dval=SKGServices::stringToDouble(val);
    32. if (role == Qt::DisplayRole) {
    33. QString unit=" ";
    34. if (QString::compare(att, "f_QUANTITY", Qt::CaseInsensitive)!=0 && QString::compare(att, "f_REALQUANTITY", Qt::CaseInsensitive)!=0) {
    35. unit=((SKGDocumentBank*) getDocument())->getPrimaryUnit();
    36. if (getRealTable()=="unitvalue" && !cacheUnit.isEmpty()) {
    37. unit=cacheUnit;
    38. }
    39. }
    40. return KGlobal::locale()->formatMoney (dval, unit, 2);
    41. } else {
    42. return dval;
    43. }
    44. } else if (att.startsWith("i_")) {
    45. if (att=="i_number" && val=="0") return "";
    46. return SKGServices::stringToInt(val);
    47. } else if (att.startsWith("d_")) {
    48. QDate dval=SKGServices::stringToTime(val).date();
    49. if (role == Qt::DisplayRole) {
    50. return KGlobal::locale()->formatDate (dval, KLocale::FancyShortDate);
    51. } else {
    52. return dval;
    53. }
    54. }
    55. return val;
    56. }
    57. case Qt::DecorationRole: {
    58. //decoration
    59. if (index.column() == 1 && getRealTable()=="account") {
    60. QString t_icon=obj->getAttribute("t_icon");
    61. if (t_icon.isEmpty()) t_icon=obj->getAttribute("t_ICON");
    62. if (!t_icon.isEmpty()) {
    63. QDir dirLogo(KStandardDirs::locate("data", QString::fromLatin1("skrooge/images/logo/")+KGlobal::locale()->language()+'/'));
    64. return qVariantFromValue(QIcon(dirLogo.absoluteFilePath(t_icon)));
    65. }
    66. } else if (index.column() == 0 && getRealTable()=="category") {
    67. QString t_TYPEEXPENSE=obj->getAttribute("t_TYPEEXPENSE");
    68. if (t_TYPEEXPENSE==tr("Expense")) return KIcon("skrooge_category_expense");
    69. else if (t_TYPEEXPENSE==tr("Income")) return KIcon("skrooge_category_income");
    70. return KIcon("skrooge_category");
    71. } else {
    72. QString att=listAttibutes[index.column()];
    73.  
    74. if (getRealTable()=="operation" || getRealTable()=="recurrentoperation") {
    75. if (att=="t_mode") {
    76. if (obj->getAttribute("i_group_id")!="0") return KIcon("skrooge_transfer");
    77. } else if (att=="t_CATEGORY") {
    78. if (SKGServices::stringToInt(obj->getAttribute("i_NBSUBCATEGORY"))>1) return KIcon("skrooge_split");
    79. } else if (att=="t_comment" && getRealTable()=="operation") {
    80. if (obj->getAttribute("i_NBRECURRENT")!="0") return KIcon("skrooge_schedule_origin");
    81. else if (obj->getAttribute("r_recurrentoperation_id")!="0") return KIcon("chronometer");
    82. } else if (att=="t_bookmarked" && obj->getAttribute("t_bookmarked")=="Y") return KIcon("rating");
    83. }
    84. }
    85. break;
    86. }
    87. case Qt::TextColorRole: {
    88. //Text color
    89. QString att=listAttibutes[index.column()];
    90. if (getRealTable()=="recurrentoperation" &&
    91. att=="d_DUEDATE" &&
    92. SKGServices::stringToTime(obj->getAttribute("d_DUEDATE")).date()<=QDate::currentDate())
    93. return qVariantFromValue(QColor(Qt::red));
    94. break;
    95. }
    96. case Qt::CheckStateRole: {
    97. //CheckState
    98. QString att=listAttibutes[index.column()];
    99. if (getRealTable()=="operation" && att=="t_status") {
    100. QString t_status=obj->getAttribute("t_status");
    101. if (t_status=="P") return Qt::PartiallyChecked;
    102. else if (t_status=="C") return Qt::Checked;
    103. else if (t_status=="N") return Qt::Unchecked;
    104. } else if (getRealTable()=="account" && att=="t_close") {
    105. QString t_status=obj->getAttribute("t_close");
    106. if (t_status=="Y") return Qt::Checked;
    107. else return Qt::Unchecked;
    108. } else if (getRealTable()=="recurrentoperation" && att=="i_auto_write_days") {
    109. QString t_auto_write=obj->getAttribute("t_auto_write");
    110. if (t_auto_write=="Y") return Qt::Checked;
    111. else return Qt::Unchecked;
    112. } else if (getRealTable()=="recurrentoperation" && att=="i_warn_days") {
    113. QString t_auto_write=obj->getAttribute("t_warn");
    114. if (t_auto_write=="Y") return Qt::Checked;
    115. else return Qt::Unchecked;
    116. }
    117. break;
    118. }
    119. case Qt::ToolTipRole: {
    120. //Tooltip
    121. QString secondaryUnit=((SKGDocumentBank*) getDocument())->getSecondaryUnit();
    122. if (!secondaryUnit.isEmpty()) {
    123. QString att=listAttibutes[index.column()];
    124. if (att.startsWith("f_") && att!="f_QUANTITY" && att!="f_REALQUANTITY") {
    125. double unitval=((SKGDocumentBank*) getDocument())->getSecondaryUnitValue();
    126. if (unitval) {
    127. double dval=SKGServices::stringToDouble(obj->getAttribute(att))/unitval;
    128. return KGlobal::locale()->formatMoney (dval, secondaryUnit, 2);
    129. }
    130. }
    131. }
    132. break;
    133. }
    134. default: {
    135. }
    136. }
    137. return SKGObjectModelBase::data(index, role);
    138. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView performances

    Quote Originally Posted by miraks View Post
    In fact reset is called only 3 times for this table:
    So reduce it to 0. There is a 99% chance you don't need it.

    So, I can't reduce the number of call to reset.
    Sure you can. You can remove all rows and insert new ones, if you have to. It'll be much faster than calling reset. And you don't have to reset an empty model.

    Your data() implementations are very complicated, try simplifying them. Here are some hints:
    - don't compare strings, compare enums, single characters, ints or hashes from strings
    - cache, cache, cache
    * don't recompute data, cache it - there is a chance it'll be needed soon
    * if you compute data for the item, compute not only the display role, but all roles - the view will query for more than one role for each index, why repeat calculations?

  6. #6
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView performances

    Hi,

    I replaced all calls to reset by something based on beginRemoveRows + endRemoveRows + beginInsertRows + endInsertRows.

    But I still have the same performances (bad performances ) and the same number of calls on data method:
    Qt Code:
    1. ##methode nb call millisecondes moyenne min max propre moyenne propre %
    2. ##SKGObjectModel::data 2706598 46342,4 0,02 0 64,25 35899,5 0,01 33,75%
    3. ##QAbstractItemModel::refresh-fill 14 48237 3445,5 0,09 47583,1 19442,2 1388,73 18,28%
    4. ##SKGObjectModelBase::rowCount 2709500 15354,5 0,01 0 53,88 15354,5 0,01 14,44%
    5. ##SKGObjectModelBase::index 2709435 13351,1 0 0 51,89 13351,1 0 12,55%
    6. ##SKGObjectModelBase::data 2353264 11256,9 0 0 64,2 10569,1 0 9,94%
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView performances

    Did you reimplement data() the way I suggested?

  8. #8
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView performances

    Do not use reset() as you could,because reset() will clear the state of the items in the table, for example, the selected state. And the beginInsertRows(), endInsertRows() will reduce the efficiency. You could emit the signals layoutAboutToBeChanged()before you insert warnings,layoutChanged() after you insert warnings.

    The tableview could be very efficent, I have tried to display 100,000 items, and there is no obvious delay.

    er, I have a question, what tool do u use to test your codes' efficency?
    Last edited by calmspeaker; 26th November 2008 at 02:05.
    Jerry

  9. #9
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView performances

    Did you reimplement data() the way I suggested?
    Not yet.
    Do not use reset() as you could,because reset() will clear the state of the items in the table, for example, the selected state. And the beginInsertRows(), endInsertRows() will reduce the efficiency. You could emit the signals layoutAboutToBeChanged()before you insert warnings,layoutChanged() after you insert warnings.
    In any case, in my scenario, I have to fill the table with around 3400 new lines.
    At the beginning the table contains 20 lines.
    After a user action, the table must contain around 3400 new lines.
    I will try with layoutAboutToBeChanged() and layoutChanged().
    The tableview could be very efficient, I have tried to display 100,000 items, and there is no obvious delay.
    Did you tried with decorations, colors, alignment ?
    I noticed bad performances just by adding background color.
    what tool do u use to test your codes' efficency?
    My own component.
    In fact, my traces system is able (with some build directives activated) to compute the time consumed by a part of code (a method for example).
    This system is less time consuming that something like Callgrind.
    Last edited by jacek; 26th November 2008 at 18:53. Reason: changed [code] to [quote]

  10. #10
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView performances

    In any case, in my scenario, I have to fill the table with around 3400 new lines.
    At the beginning the table contains 20 lines.
    After a user action, the table must contain around 3400 new lines.
    I suggest you only call the pair signal(beginlayoutchanged, layoutchanged) once, in your situation, that is a way to improve the efficiency.
    Did you tried with decorations, colors, alignment ?
    I noticed bad performances just by adding background color.
    I only tried to changed all the items' background color every per second.The efficiency is acceptable.

    My own component.
    In fact, my traces system is able (with some build directives activated) to compute the time consumed by a part of code (a method for example).
    This system is less time consuming that something like Callgrind.
    Could it be shared?
    Jerry

  11. The following user says thank you to calmspeaker for this useful post:

    miraks (30th November 2008)

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView performances

    Have you tried gprof? It's faster than callgrind because it doesn't emulate the cpu and it's standard, so there are tools to use it. You can use it with GCC only, but I take it that's not a problem for you

  13. #12
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView performances

    Hi calmspeaker,

    I prepared for you a package containing:
    1-A class managing errors with history.
    2-A class managing indented traces with error and profiling.
    3-A document to explain how to use it.

    I hope it will help you.
    If you need help, contact me.

    I will test your proposal.
    Attached Files Attached Files

  14. #13
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView performances

    Hi,

    Here is the result of my test with layoutAboutToBeChanged + layoutChanged.

    Without this modification, I get:
    Qt Code:
    1. ##methode nb call millisecondes moyenne min max propre moyenne propre %
    2. ##SKGObjectModel::data 2705890 43950,9 0,02 0 60,99 31727,7 0,01 39,24%
    3. ##SKGObjectModelBase::data 2347017 12969,1 0,01 0 37,98 12309,6 0,01 15,23%
    4. ##SKGObjectModelBase::rowCount 2707786 10864,1 0 0 22,39 10864,1 0 13,44%
    5. ##SKGObjectModelBase::index 2707746 9032,57 0 0 27,68 9032,57 0 11,17%
    6. ##QAbstractItemModel::reset-fill 14 21129,6 1509,26 0,19 20674,1 8237,73 588,41 10,19%
    7. ##SKGObjectModelBase::headerData 251522 4541,63 0,02 0 16,52 3054,3 0,01 3,78%
    8. ##SKGServices::executeSelectSqliteOrder(QSqlDatabase) 174 2351,37 13,51 0,03 730,59 2351,37 13,51 2,91%
    9. ##SKGMainPanel::SKGMainPanel 1 4144,91 4144,91 4144,91 4144,91 820,56 820,56 1,01%
    To copy to clipboard, switch view to plain text mode 

    With the modification:
    Qt Code:
    1. ##methode nb call millisecondes moyenne min max propre moyenne propre %
    2. ##SKGObjectModel::data 1939034 31138,4 0,02 0 32,87 22583,8 0,01 37,16%
    3. ##SKGObjectModelBase::data 1667650 9058,82 0,01 0 27,76 8592,84 0,01 14,14%
    4. ##QAbstractItemModel::reset-fill 14 21189,3 1513,52 0,13 20886,5 8319,58 594,26 13,69%
    5. ##SKGObjectModelBase::rowCount 1941008 7398,6 0 0 35,16 7398,6 0 12,17%
    6. ##SKGObjectModelBase::index 1940968 6369,83 0 0 20,05 6369,83 0 10,48%
    7. ##SKGServices::executeSelectSqliteOrder(QSqlDatabase) 174 2528,14 14,53 0,03 759,23 2528,14 14,53 4,16%
    8. ##SKGObjectModelBase::headerData 170665 2962,19 0,02 0 12,09 1976,83 0,01 3,25%
    9. ##SKGServices::executeSqliteOrder(QSqlDatabase) 379 1612,22 4,25 0,03 533,94 831,15 2,19 1,37%
    10. ##SKGMainPanel::SKGMainPanel 1 3931,13 3931,13 3931,13 3931,13 715,1 715,1 1,18%
    To copy to clipboard, switch view to plain text mode 

    Conclusion:
    It's better because the number of call reduced.
    It's not enough.

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView performances

    I really suggest to modify the implementation of data(). It is currently very inefficient and it's one of the most often called methods.

  16. #15
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView performances

    Quote Originally Posted by wysota View Post
    I really suggest to modify the implementation of data(). It is currently very inefficient and it's one of the most often called methods.
    I will try but it's not so easy !
    I will take you informed.

    In any case, thank you for your help.

  17. #16
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView performances

    Hi wysota,

    I have got 2 bad news:

    1-I optimized data method and after that, I commented in data methods all the code concerning decoration, tooltip, alignment, etc to keep only the text. Even with this, I win only 6% of performances. .
    Conclusion: even with perfect code in data, I won't have good performances.

    2-The solution based on layoutAboutToBeChanged + layoutChanged generates some regressions.
    (indexes seems to be not recomputed and so are still pointing on deleted internal data).

    I don't know what to do.

    PS1: I attached my new implementation.
    PS2: I don't know if it's very important, but I use a proxy (filter & sort) too.
    Attached Files Attached Files

  18. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView performances

    The implementation is still very inefficient. You are still comparing strings instead of enums or numbers and you don't do any serious caching of calculated data.

    6% performance gain is already much, don't underestimate it.

  19. #18
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView performances

    Hi wysota,

    Today, I have got a good new.
    I understood why I have so bad performances.
    In fact, it's due to these lines:
    Qt Code:
    1. ui.kOperationView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
    2. ui.kOperationView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
    To copy to clipboard, switch view to plain text mode 

    If I comment these lines, I have got:
    Qt Code:
    1. ##methode , nb call , millisecondes , moyenne , min , max , propre , moyenne propre
    2. ##SKGServices::executeSelectSqliteOrder(QSqlDatabase) , 173 , 2250.3 , 13.0075 , 0.0319843 , 757.705 , 2250.3 , 13.0075
    3. ##SKGObjectModelBase::data , 77777 , 2022.72 , 0.0260067 , 0.00187886 , 17.3499 , 2011.33 , 0.0258602
    4. ##SKGObjectModelBase::refresh-reset , 13 , 4078.05 , 313.696 , 0.00701368 , 3962.67 , 1081.16 , 83.166
    5. ##SKGObjectModel::data , 71620 , 2738.77 , 0.0382403 , 0.00292969 , 17.3791 , 776.344 , 0.0108398
    6. ##SKGServices::executeSqliteOrder(QSqlDatabase) , 379 , 1319.9 , 3.48257 , 0.0279003 , 444.459 , 679.188 , 1.79205
    7. ##SKGMainPanel::SKGMainPanel , 1 , 2419.67 , 2419.67 , 2419.67 , 2419.67 , 372.141 , 372.141
    8. ##SKGObjectModelBase::index , 73266 , 295.21 , 0.00402929 , 0.00190628 , 10.6721 , 295.21 , 0.00402929
    9. ##SKGObjectModelBase::rowCount , 73305 , 223.636 , 0.00305076 , 0.00187886 , 11.12 , 223.636 , 0.00305076
    10. ##SKGObjectModelBase::clear , 17 , 201.88 , 11.8753 , 0.00792778 , 176.784 , 201.88 , 11.8753
    11. ##SKGObjectBase::getObjects , 62 , 1078.61 , 17.3969 , 0.0670469 , 932.943 , 184.245 , 2.9717
    12. ##SKGObjectModelBase::headerData , 9244 , 137.556 , 0.0148806 , 0.00188088 , 1.31897 , 104.604 , 0.0113158
    13. ##SKGSortFilterProxyModel::filterAcceptsRow , 4022 , 336.626 , 0.0836961 , 0.023957 , 0.784051 , 90.5983 , 0.0225257
    To copy to clipboard, switch view to plain text mode 

    As you can see, the number of calls is drastically reduced and performances are better (before 43s into data method, now 2s into data method ==> it's better than 6% ).

    Is it normal to have so bad performances when ResizeToContents is used ?

  20. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView performances

    Yes, that's normal. sizeHint is queried all the time which in turns calls data() all the time, etc. I thought you knew that so I didn't even bother to mention it, sorry

    But honestly it's because of your hand-crafted profiler - it doesn't monitor methods which are called automatically by Qt or that are implemented by Qt, hence no references to sizeHint reading and hence my impression you weren't resizing columns to contents.

  21. The following user says thank you to wysota for this useful post:

    miraks (1st December 2008)

Similar Threads

  1. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 17:13
  2. QTableView in ui with model/delegate
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 6th November 2008, 23:00
  3. QTableView
    By dragon in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2008, 16:53
  4. make QTableView work as a multi-column list view
    By wesley in forum Qt Programming
    Replies: 1
    Last Post: 11th March 2008, 14:43
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.