#1 2021-10-14 13:19:36

wxinix
Member
Registered: 2020-09-07
Posts: 121

What is the best(fastest) way of loading a JSON file into TDocVariant?

Using this sample data https://gist.github.com/wxinix/2162c9c1 … b157f1ce6c

The following code takes about 6 ms.  Is that the normal speed?   Any other approaches that might be faster?

  FData: Variant := _JsonFast(AData);
  FDataLC: PDocVariantData := DocVariantData(FData.LC);

Offline

#2 2021-10-14 15:14:38

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,237
Website

Re: What is the best(fastest) way of loading a JSON file into TDocVariant?

For almost 1MB of JSON it parses 166MB/s which makes sense.

If you want to avoid a temporary copy, you could use directly TDocVariantData.InitJsonInPlace() but it will modify the AData variable in-place.
You could try the dvoJsonParseDoNotGuessCount option for perhaps slightly faster process too.

My guess is that using a record with nested types would be faster than TDocVariant because it doesn't need to store the field names.
Almost twice faster than TDocVariant from my numbers when you parse it, and instant when you use it (no field name lookup, but directly get the value per field).

Offline

Board footer

Powered by FluxBB