Results 1 to 5 of 5

Thread: Why is QBuffer's close call so slow?

  1. #1
    Join Date
    Apr 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Why is QBuffer's close call so slow?

    I have the following piece of code:

    Qt Code:
    1. void Class::processElements(const QString & aInputFile,
    2. const QString & aNodeName)
    3. {
    4. QFile queryFile(QString(":queries/") + "syncronizationresponse.xq");
    5. if (queryFile.open(QFile::ReadOnly))
    6. {
    7. QString queryString(queryFile.readAll());
    8.  
    9. QFile sourceDocument(aInputFile);
    10. if (sourceDocument.open(QIODevice::ReadOnly))
    11. {
    12. //Create query
    13. QXmlQuery query;
    14. query.bindVariable("inputDocument", &sourceDocument);
    15. query.bindVariable("bindedVariable", QVariant(aNodeName));
    16. query.setQuery(queryString);
    17.  
    18. if(query.isValid())
    19. {
    20. //Evaluate
    21. QByteArray byteArray;
    22. QBuffer buffer(&byteArray);
    23. if (buffer.open(QIODevice::ReadWrite))
    24. {
    25. QXmlSerializer xmlSerializer(query, &buffer);
    26. if (query.evaluateTo(&xmlSerializer))
    27. {
    28. //Process the stuff in the byteArray
    29. }
    30. else
    31. qDebug() << "Evaluation to serializer failed";
    32. }
    33. else
    34. {
    35. qDebug() << "Opening output buffer failed " << buffer.errorString();
    36. }
    37. //Starting to close buffer for "ROUTE" "ke 8. huhti 06:53:37 2009"
    38. buffer.close();
    39. //Finished closing buffer for "ROUTE" "ke 8. huhti 06:53:37 2009"
    40. }
    41. else
    42. {
    43. qDebug() << "XmlQuery failed";
    44. }
    45. }
    46. else
    47. {
    48. qDebug() << "Opening input file failed " << sourceDocument.errorString();
    49. }
    50. //Starting to close source document for "ROUTE" "ke 8. huhti 06:53:46 2009"
    51. sourceDocument.close();
    52. //Finished closing source document for "ROUTE" "ke 8. huhti 06:53:46 2009"
    53. }
    54. else
    55. {
    56. qDebug() << "Opening query file failed " << queryFile.errorString();
    57. }
    58. //Starting to close query file for "ROUTE" "ke 8. huhti 06:53:46 2009"
    59. queryFile.close();
    60. //Finished closing query file for "ROUTE" "ke 8. huhti 06:53:46 2009"
    61. }
    To copy to clipboard, switch view to plain text mode 

    Who can tell me why the heck it takes 9 seconds from buffer.close(); to sourceDocument.close(); ?? There should not be anything that slows it down? Unless it has something to do with signals that the QBuffer emits when close is called? Does anyone know what makes close call to QBuffer so slow??

    BR, Kimmo

  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: Why is QBuffer's close call so slow?

    It looks like close finishes immediately. It seems that it's the destructors that might be causing the slowdown. What is the point of using the buffer if you destroy it immediately afterwards without doing anything with the data saved in it? What happens if you move the buffer and byte array declarations outside the most inner scope?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why is QBuffer's close call so slow?

    What is the point of using the buffer if you destroy it immediately afterwards without doing anything with the data saved in it
    The section where it stands "//Process the stuff in the byteArray" is where I use the byteArray. I just ripped from this code sniplet that part out.

    What happens if you move the buffer and byte array declarations outside the most inner scope
    I haven't tried I'll see what happens..

  4. #4
    Join Date
    Apr 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why is QBuffer's close call so slow?

    After further investigation I found out that it is the deletion of "QXmlQuery query" that takes ages. Wysota's tip for moving declations outside the if clause gave me the hint that it could be some destruction (when leaving the if) that is taking such a long time. I moved (byteArray, buffer, sourceDocument and query) declarations to the beging of my method and changed the creation of "QXmlQuery query" to "QXmlQuery* query = new QXmlQuery();". I now see that

    Qt Code:
    1. //Starting to delete query "ROUTE" "ke 8. huhti 09:53:36 2009"
    2. if (query)
    3. delete query;
    4. //Finished deleting query "ROUTE" "ke 8. huhti 09:53:46 2009"
    To copy to clipboard, switch view to plain text mode 

    Any idea why deletion of QXmlQuery takes such a long time.

  5. #5
    Join Date
    Apr 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why is QBuffer's close call so slow?

    I also noticed that it does not help to move the QXmlQuery to class member and pass that to the method as a varaible. This way it would only need to be deleted once after all method calls. Anyway, this is because then QXmlQuery's

    "query->bindVariable("inputDocument", &sourceDocument);"

    will hold on the second method call. Most likely as to documentation "If name has already been bound, its previous binding will be overridden". So it is the realising of something that is slowing it down..

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.