VBA-tools / VBA-JSON

JSON conversion and parsing for VBA
MIT License
1.74k stars 566 forks source link

Speed issue #269

Open budddemarketing opened 3 months ago

budddemarketing commented 3 months ago

I got this working for an Access Query I needed to export to JSON each month. Did a top 10 for testing and it was working well. Finished in seconds

Now I tried it with 60k records and ~20 columns and while I wasn't expecting speed racer it's slow. I have let it run for hours so far and haven't gotten anywhere.

Maybe make a temp table first might help a little instead of the query. Maybe but that is grasping.

When I stepped though it nothing jumped out at me. Anyone else running this with larger record-sets?

Nick-vanGemeren commented 3 months ago

First, a bit of maths.

The killer will be that large output string. Issue #203 showed that problems can occur with strings of 10M characters. So maybe your process failed after 6 hours with an ‘out of string space’ error or similar.

It may be possible to rework the internal ‘buffer’ mechanism to minimise using large strings internally, but the large final string would still remain. So I don’t know if that would help much.

You haven’t mentioned why you need JSON output. CSV output will be half the size and can be directly loaded into Excel. Maybe your database can export directly in CSV or JSON format.

If you really have to program JSON output, it may be best to write to a file with ‘records’ for each row including an initial character to form the top-level JSON Array:

    [<JSON for row 1>
    ,<JSON for row 2>
    …
    ,<JSON for row n>
    ]

It may still take a long time, but there will be no issues with ballooning strings or task memory.