Results 1 to 20 of 35

Thread: Big Problem search through huge amount of data ca 30 000 strings takes to long

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2015
    Posts
    67

    Default Big Problem search through huge amount of data ca 30 000 strings takes to long

    Hello,

    this is my Code:

    Qt Code:
    1. void SomeClass::searchIn_identifier_listWidget()
    2. {
    3. QList<Identifier*> tempList;
    4.  
    5. QString text0 = ui->identifier_lineEdit_search_0->text();
    6. QString text1 = ui->identifier_lineEdit_search_1->text();
    7. QString text2 = ui->identifier_lineEdit_search_2->text();
    8. QString text3 = ui->identifier_lineEdit_search_3->text();
    9. QString text4 = ui->identifier_lineEdit_search_4->text();
    10.  
    11. for (int i = 0; i < Storage::identifier.count(); i++) {
    12. if (Storage::identifier.at(i)->dataString.contains(text0,Qt::CaseInsensitive) &&
    13. Storage::identifier.at(i)->dataString.contains(text1,Qt::CaseInsensitive) &&
    14. Storage::identifier.at(i)->dataString.contains(text2,Qt::CaseInsensitive) &&
    15. Storage::identifier.at(i)->dataString.contains(text3,Qt::CaseInsensitive) &&
    16. Storage::identifier.at(i)->dataString.contains(text4,Qt::CaseInsensitive))
    17. {
    18. tempList << Storage::identifier.at(i);
    19. }
    20. }
    21.  
    22. ui->identifier_listWidget->clear();
    23. for (int i = 0; i < tempList.count(); i++) {
    24. QTest::qWait(1);
    25. listWidget_addItemPlusTooltip(ui->identifier_listWidget,tempList.at(i)->dataString);
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

    So as you can see i want to search though someting in this case a QList and load the Strings into the ListWidget which match the search. The algorythm should stay like this I think. It takes like minutes until the Widget is filled with the new data. i have like 30 000 strings in this List. And all GUI should stay responsive to the user thats why the qWait is there. Maybe thats why it is so slow, but how can the GUI stay responsive without qwait?

    What can I do???

    Can somebody help me?

    edit: Without qwait the whole GUI in ther widget where this QListWidget is is locked. And it also takes like 1 minute to process all data into the QListWidget

    thx
    Last edited by Ini; 21st March 2016 at 03:22.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    First optimization - five times less method Storage::identifier.at(i) calls :
    Qt Code:
    1. QString temp_str;
    2. for (int i = 0; i < Storage::identifier.count(); i++) {
    3. temp_str = Storage::identifier.at(i)->dataString;
    4. if (temp_str.contains(text0,Qt::CaseInsensitive) &&
    5. temp_str.contains(text1,Qt::CaseInsensitive) &&
    6. temp_str.contains(text2,Qt::CaseInsensitive) &&
    7. temp_str.contains(text3,Qt::CaseInsensitive) &&
    8. temp_str.contains(text4,Qt::CaseInsensitive))
    9. {
    10. tempList << Storage::identifier.at(i);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Also, since QTest::qWait() suggests this is a unit test, is it really that problematic?

    In a real application blocking the UI would be bad, but in an automated test you will have to wait for the result state anyway.

    Cheers,
    _

  4. #4
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Can qWait not stay in the endprogramm?

    I cannot cut qWait cause GUI stays unresponsive then. I would consider this as big problem...


    Added after 20 minutes:


    Quote Originally Posted by Lesiok View Post
    First optimization - five times less method Storage::identifier.at(i) calls :
    Qt Code:
    1. QString temp_str;
    2. for (int i = 0; i < Storage::identifier.count(); i++) {
    3. temp_str = Storage::identifier.at(i)->dataString;
    4. if (temp_str.contains(text0,Qt::CaseInsensitive) &&
    5. temp_str.contains(text1,Qt::CaseInsensitive) &&
    6. temp_str.contains(text2,Qt::CaseInsensitive) &&
    7. temp_str.contains(text3,Qt::CaseInsensitive) &&
    8. temp_str.contains(text4,Qt::CaseInsensitive))
    9. {
    10. tempList << Storage::identifier.at(i);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    is this really faster? whats the problem with .at(i) calls
    Last edited by Ini; 21st March 2016 at 10:50.

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Quote Originally Posted by Ini View Post


    Added after 20 minutes:

    is this really faster? whats the problem with .at(i) calls
    The problem is "this is a procedure calling". What do you think is faster: one call or five calls ?
    Besides, my experience is that many operations on the Qt containers is very slow in debug mode because of the control parameters with ASSERT.

    PS.

    Have you tried to determine which loop will give you such a long time?

  6. #6
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    I dont know im not expert in memeory management. In my opionion both "point" to a location. I will check on that.

    edit: I work in Release Mode.

    But thats really not the Problem. Problem is the second loop.

    I added qApp->processEvents. That helps but then there is a another Problem.
    This Slot is connected to textChanged() of the LineEdits. So when text changes the slot will get triggerd, then text changes again, and it seems the slot then stops and performs the new instance of the slotcall and when this new instance is finsihed the old one continues. Am I right there? How to solve that upcoming problem?

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Quote Originally Posted by Ini View Post
    Can qWait not stay in the endprogramm?
    If you want the real program to link to QtTest, sure.
    Usually one doesn't want artifical dependencies.

    Quote Originally Posted by Ini View Post
    I cannot cut qWait cause GUI stays unresponsive then. I would consider this as big problem...
    Then I would suggest looking for a solution instead.

    E.g. putting the result list into a model and having a QListView work on that model.

    Cheers,
    _

  8. #8
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Quote Originally Posted by anda_skoa View Post
    If you want the real program to link to QtTest, sure.
    Usually one doesn't want artifical dependencies.


    Then I would suggest looking for a solution instead.

    E.g. putting the result list into a model and having a QListView work on that model.

    Cheers,
    _
    why is that faster then QListWidget

    "Usually one doesn't want artifical dependencies."

    I dont find a good description what that is. Can you explain pls?

  9. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Quote Originally Posted by Ini View Post
    I dont know im not expert in memeory management. In my opionion both "point" to a location.
    Yes, but one is a direct "pointer" to the data, the other is repeatedly calculating the "pointer".
    Using a variable can even more likely lead to the pointer to be cached by the CPU than the result of a function evaluation which just incidentally (as far as the CPU knowns) returns the same value five times in a row.

    Quote Originally Posted by Ini View Post
    I added qApp->processEvents. That helps but then there is a another Problem.
    Yes, this new problem is called "nested event loop".

    Quote Originally Posted by Ini View Post
    This Slot is connected to textChanged() of the LineEdits. So when text changes the slot will get triggerd, then text changes again, and it seems the slot then stops and performs the new instance of the slotcall and when this new instance is finsihed the old one continues.
    Yes, nested event loops can lead to behavior similar to re-entrancy.

    Quote Originally Posted by Ini View Post
    why is that faster then QListWidget
    Because you don't have to create all items, a list view only displays as many entries as it can fit.

    Quote Originally Posted by Ini View Post
    I dont find a good description what that is. Can you explain pls?
    A dependency on a library that you actually don't need.

    Cheers,
    _

Similar Threads

  1. Replies: 9
    Last Post: 29th March 2011, 09:55
  2. QTextEdit loading takes long time
    By sreedhar in forum Qt Programming
    Replies: 12
    Last Post: 21st March 2011, 10:29
  3. Problem: the Application Takes very long time to build
    By Ma7moud El-Naggar in forum Qt Programming
    Replies: 5
    Last Post: 20th November 2010, 06:26
  4. [QTableWidget] clearing a big table takes so long!
    By punkypogo in forum Qt Programming
    Replies: 4
    Last Post: 5th August 2010, 13:52
  5. QImage::scaled takes long time
    By nrabara in forum Qt Programming
    Replies: 0
    Last Post: 15th December 2009, 12:19

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.