JSONItem.ToString(); performance;

  1. 5 days ago

    Hans-Norbert G

    is not verified Nov 7 Pre-Release Testers, Xojo Pro

    Hello!

    As this is a general question about JSONItem.ToString()-performance, I have no source code as an example.

    I have a database request which results in an about 848KB size for a string after JSONItem.ToString().
    The table was 10 columns and 4200 rows; the JSONItem object is already built up.
    I am only talking about performance of the ToString()-method.
    I already measured encodeBase64 and database request itself and converting to JSONItem -> they are all very fast!

    The call to ToString() needed about 4 seconds.

    First, is this speed to be assumed for the given result bytes amount?

    My guess is the following: the performance is not so good because no string builder is used internally but string is repeatedly extended on and on.
    Hopefully I am wrong here.

    So, last question, is there an add-on/class from Monkeybread Software for faster JSONItem-to-string handling?
    Unfortunately, did not find it.

    Any idea really apreciated!

    Regards

  2. Derk J

    Nov 8 Pre-Release Testers, Xojo Pro

    Did you try "ParseJSON" and "GenerateJSON" ? Those may be faster

  3. Hans-Norbert G

    is not verified Nov 8 Pre-Release Testers, Xojo Pro

    I have a JSONItem and need a string.

    Just "found" Monkeybread Software's JSONMBS and will switch to this; should work correct.

  4. Hans-Norbert G

    is not verified Nov 8 Pre-Release Testers, Xojo Pro
    Edited 5 days ago

    That's funny.

    ObjJSONMBS.toString() is very fast.

    But this

    J.AddItemToArray(JSONMBS.NewStringNode(Field.asStringValue))

    seems to be far slower as JSONMBS.NewStringNode(Field.asStringValue) seems to be slow...

    Any ideas how to solve this?

  5. Derk J

    Nov 8 Pre-Release Testers, Xojo Pro
    Edited 5 days ago

    @Hans-NorbertGratzal I have a JSONItem and need a string.

    Just "found" Monkeybread Software's JSONMBS and will switch to this; should work correct.

    @Hans-NorbertGratzal I have a JSONItem and need a string.

    Just "found" Monkeybread Software's JSONMBS and will switch to this; should work correct.

    The parseJSON without Xojo.Core is string based

    You can contact @ChristianSchmitz for details about his classes

  6. Hans-Norbert G

    is not verified Nov 8 Pre-Release Testers, Xojo Pro

    Hello Derk!

    What have ParseJSON and GenerateJSON to do with JSONItem toString()???

    As, I wrote ToString() for JSONItem is slow.
    And AddItemToArray() or JSONMBS.newStringNode("") seems to be slow.

    The benchmark example which is given for MonkeyBread Software's JSONMBS also shows that JSON creation is slower for JSONMBS compared to Xojo's JSONItem; which was horrible for me to see:-(

    As I serialize the data catched from the database via web socket, I could build up the JSON string as what it is a string.
    But as the string gets big (848KB), I would bet to have the same problem.

    So, next task for me is to see if StringBuilder is avaiable for Xojo.

    Still ned help with this;-)

    Thanks!

  7. Hans-Norbert G

    is not verified Nov 8 Pre-Release Testers, Xojo Pro

    Finally, this method
    J = JSONMBS.NewStringArray(D)
    where D is a string array is even slower then toString from JSONItem...

  8. Hans-Norbert G

    is not verified Nov 8 Pre-Release Testers, Xojo Pro

    Damn... I forgot ChilkatSoft... That JSON will be definitely-hopefully fast;-)

    Ok, I will try some tests with it and close this conversation hopefully soon;-)

  9. Kem T

    Nov 8 Pre-Release Testers, Xojo Pro, XDC Speakers Connecticut

    Another option for you is my drop in replacement, JSONItem_MTC. I think you'll find it's quite a bit faster.

    https://github.com/ktekinay/JSONItem_MTC

  10. Derk J

    Nov 8 Pre-Release Testers, Xojo Pro
    Edited 5 days ago

    @Hans-NorbertGratzal Hello Derk!

    What have ParseJSON and GenerateJSON to do with JSONItem toString()???

    As, I wrote ToString() for JSONItem is slow.
    And AddItemToArray() or JSONMBS.newStringNode("") seems to be slow.

    The benchmark example which is given for MonkeyBread Software's JSONMBS also shows that JSON creation is slower for JSONMBS compared to Xojo's JSONItem; which was horrible for me to see:-(

    As I serialize the data catched from the database via web socket, I could build up the JSON string as what it is a string.
    But as the string gets big (848KB), I would bet to have the same problem.

    So, next task for me is to see if StringBuilder is avaiable for Xojo.

    Still ned help with this;-)

    Thanks!

    You can use those functions to parseJSON or GenerateJSON from or to a dictionary instead of using JSONItem.
    JSONItem is known for being "slow" @Kem T has some classes Einhugur has json plugins and MBS has JSON plugins
    and ChilkatSoft all are Alternatives to JSONItem usage.
    If .ToString is too slow, don't expect it to get faster by "saying JSONItem.ToString is slow". So you might wanna use one of the alternatives instead to workaround your issue.

  11. Hans-Norbert G

    is not verified Nov 8 Pre-Release Testers, Xojo Pro

    Hello Derk,
    hello Kem,

    thanks a lot for Your help!!!

    I will try these advices and see if I can speed everything up a little.

  12. Thom M

    Nov 8 Pre-Release Testers Greater Hartford Area, CT

    I did some performance testing with all the available JSON options in Xojo, with an entry for Xojo 2019r2’s ParseJSON still coming.

    https://thezaz.com/blog/json_performance_tests_round_2

    But the TLDR is: if you need pure performance, use Xojo.GenerateJSON or JSONMBS.Convert.

  13. Norman P

    Nov 8 Pre-Release Testers, Xojo Pro great-white-software.com/blog

    did you happen to evaluate "correctness" ?
    they should all be able to encode using one and decode using another no ?

  14. 3 days ago

    Hans-Norbert G

    is not verified Nov 10 Pre-Release Testers, Xojo Pro
    Edited 3 days ago

    So, finally I switched to ChilkatSoft.JsonObject with

    System.DebugLog("sendClientWebSocketResponseC;before J.Emit(): " + cstr(DT.getTimestamp()))
    Res = J.Emit()
    System.DebugLog("sendClientWebSocketResponseC; after J.Emit(): " + cstr(DT.getTimestamp()))

    Result is:

    sendClientWebSocketResponseC;before J.Emit(): 20191110143141227
    sendClientWebSocketResponseC; after  J.Emit(): 20191110143141232

    ChilkatSoft also has a Stringbuilder object...

    Then there is only one question left: where does the name Chilkat come from???
    (No, I did not google it... ;-)

    Thanks a lot for all Your help and tips!

or Sign Up to reply!