[Development] State of "binary JSON" in 5.15+?

Stottlemyer, Brett (B.S.) bstottle at ford.com
Thu Apr 15 16:36:08 CEST 2021


Apologies if this was already sent, I meant to send yesterday and found it in a
still open window.

On 4/14/21, 12:53 AM, "Development on behalf of Thiago Macieira" <development-bounces at qt-project.org on behalf of thiago.macieira at intel.com> wrote:

    No, that was it. I assume you're caching templates which you need to modify
    slightly for each reply, not plain-text JSON.

Ahh, no.  Sorry for not being clear.  I'm the consumer of the REST API, not the
producer.

Think geographic data, where I can prefetch at low-priority, and load/process
data on-demand as location changes.

    In Qt 5, the existing methods in QJsonDocument continue to work like they have
    done since 5.0.

I think you are saying this with a different use-case in mind, and I'd like to
understand your use-case.  For my use-case, I disagree with your statement.
Qt 5.14 could memcpy and cast a QByteArray into a QJsonDocument (untested,
but by inspection of the Woboq code and the documentation saying binary JSON
was "fast for mmap").  Qt 5.15 can't, although the fromBinaryJson API is still
supported.

Under the covers (see https://codereview.qt-project.org/c/qt/qtbase/+/265312/37/src/corelib/serialization/qjsondocument.cpp#362),
after the memcpy operations:
Qt 5.14 -> return QJsonDocument(d);
Qt 5.15 -> return d->toJsonDocument();
              -> toJsonDocument() calls toJsonObject() (or toJsonArray())
	-> toJsonObject() recurses over all of the elements
(See here https://codereview.qt-project.org/c/qt/qtbase/+/265312/37/src/corelib/serialization/qbinaryjson.cpp#204)

The result is that fromBinaryData() is significantly slower than parsing the
JSON text directly, not significantly faster.  This format is different, and I'm
not sure what use-case it is better for...

Thanks,
Brett




More information about the Development mailing list