ahausladen / JsonDataObjects

JSON parser for Delphi 2009 and newer
MIT License
413 stars 160 forks source link

Best practice for improve performance on write #49

Open cesco69 opened 5 years ago

cesco69 commented 5 years ago

From my benchmark JsonDataObjects is the fastest lib for read write json in delphi, It's awersome! but is poor in documentation.

I'm searching for examples for writing large json (over 50000 nodes, less or more 90 MB) with the best performance.

Eg. is better writing the objects with the full path:

var
  Obj: TJsonObject;
  i: integer;
begin
  Obj := TJsonObject.Create;
  for i := 0 to 50000 do begin
     Obj['foo']['bar']['baz'].A['array'].Add(i);
  end;
  Obj.Free;
end;

or write by caching the parent, eg.:

var
  Obj: TJsonObject;
  aArray:  TJsonArray;
  i: integer;
begin
  Obj := TJsonObject.Create;
  aArray := Obj['foo']['bar']['baz'].A['array'];
  for i := 0 to 50000 do begin
     aArray.Add(i);
  end;
  Obj.Free;
end;

other trick and tips are welcome!