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

QXmlStreamReader inefficient with large QByteArray content

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.2, 6.3.2, 6.4.0
    • None

    Description

      When using QXmlStreamReader on a QByteArray directly, it assumes (correctly) that all bytes are available.

      Unfortunately this has two implications:

      • on scanning the XML header "<?xml ...>" (in order to detect the encoding) the complete QByteArray data is converted to UTF-16 the first time (using BOM detection or assuming UTF-8 as source encoding)
      • after encoding detection ("<?xml ... encoding="ISO-8859-1" ...>", this happens a second time (now with the specified source encoding)

      While this works fine for smaller data sets, this can be a problem with large in-memory XML data.

      Workaround is to wrap the QByteArray in a readonly QBuffer. Then data is consumed in 8 KB chunks meaning much less heap usage and decoding effort for larger data sets:

      QByteArray xml = getXml();
      
      QBuffer buffer;
      buffer.setData(xml);
      buffer.open(QIODevice::ReadOnly);
      
      QXmlStreamReader xmlReader(&buffer);
      

      This could be mentioned in the documentation (e.g. "Performance and Memory Consumption"). Or maybe some buffer size threshold could be defined that would cause QXmlStreamReader to wrap the QByteArray automatically?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            njeisecke Nils Jeisecke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes