VBA-tools / VBA-JSON

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

performance: use Array instead of Collection #255

Closed WilianZilv closed 10 months ago

Nick-vanGemeren commented 11 months ago

What performance improvements do you expect for small and very large JSON arrays? Note that every time you call ReDim Preserve the entire array is copied to a new array.

There are some backward-compatibility issues:

So your ParseArray should be available as a non-default compilation option.

Note that no maintenance is being done on this repo. Don't hold your breath for the PR.

WilianZilv commented 11 months ago

What performance improvements do you expect for small and very large JSON arrays? Note that every time you call ReDim Preserve the entire array is copied to a new array.

There are some backward-compatibility issues:

  • Collections have first element (1). Arrays have first element (0). This could be fixed in the ReDim statement.
  • Existing code may be using the Count/Add/Remove methods which are not available for Arrays.
  • Existing code may be using Typename/Vartype methods to navigate (and verify) the data structure.

So your ParseArray should be available as a non-default compilation option.

Note that no maintenance is being done on this repo. Don't hold your breath for the PR.

Actually, i forgot to explain what i mean by performance. I dont think the change by itself benefits the parser.

I did this change because i'm using json to write data in the sheet, to do that i need to convert the Collection to an array, which is too slow (i was testing with 100k values), with Collections it can take 1+ minutes, with arrays the conversion to the structure i need is much less expensive, resulting in less than a second to do so.