Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`stdJSON` parse performance

Aperta
#82 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
30/100
Tipo di issue
Refactoring
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
json
Ambito
performance

Direzione di ricerca

Start at stdJSON.CreateFromString and run the supplied parsing and stringification benchmarks against JsonConverter and JsonBag. Review how stdJSON stores children, including the IDispatch-based Dictionary, and evaluate the proposed in-class array and hash-table design. Done means the parsing benchmark improves without regressing the existing stringification result.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement lib-stdJSON

Current benchmarks

Parsing

Parsing is probably one of the most important metrics. Generally people parse json more than they do make it. So this is an important metric.

Test code
Const cmax As Long = 100
With stdJSON.Create()
  For i = 1 To 100
    With .AddObject("x" & i)
      .Add "x", "x"
      .Add "y", 100
      .Add "longString", String$(255, "x")
      With .AddArray("test")
        .Add 1
        .Add 2
        .Add 3
      End With
    End With
  Next
  Dim s As String: s = .ToString()
End With

With stdPerformance.Measure("JsonConverter", cmax)
  For i = 1 To cmax
    Call JsonConverter.ParseJson(s)
  Next
End With
With stdPerformance.Measure("JsonBag", cmax)
  For i = 1 To cmax
    Dim x As JsonBag
    Set x = New JsonBag
    x.JSON = s
  Next
End With
With stdPerformance.Measure("stdJSON", cmax)
  For i = 1 To cmax
    Call stdJSON.CreateFromString(s)
  Next
End With
Results
JsonConverter: 5641 ms (56410µs per operation)
JsonBag: 2891 ms (28910µs per operation)
stdJSON: 7234 ms (72340µs per operation)

From these results we can see that stdJSON is significantly slower at the moment than Either Tim Hall's JSON module and JsonBag.

I think JsonBag is likely getting the performance it does by using 2 collections to store it's children data? Though this is unconfirmed. This is something that needs improving in stdJSON!

Next steps

My anticipation is that if we migrate stdJSON to use a in-class Array and HashTable (instead of IDispatch based Dictionary) this will be significantly faster than the current implementation. I.E.

Type TChild
  key as string
  val as variant
  next as long
  prev as long
End Type
Type TThis
  hashes(0 to 255) as Long
  children as TChild
End Type

Stringification

For completeness, stringification is less important but is still a useful benchmark.

Test code
Const cmax As Long = 10
  With stdJSON.Create()
    For i = 1 To 1000
      With .AddObject("x" & i)
        .Add "x", "x"
        .Add "y", 100
        .Add "longString", String$(255, "x")
        With .AddArray("test")
          .Add 1
          .Add 2
          .Add 3
        End With
      End With
    Next
    Dim s As String: s = .ToString()
  End With
  
  With stdPerformance.Optimise
    Dim timHallJSON As Object: Set timHallJSON = JsonConverter.ParseJson(s)
    Dim jsBag As New JsonBag: jsBag.JSON = s
    Dim std As stdJSON: Set std = stdJSON.CreateFromString(s)
    Dim x As String
    With stdPerformance.Measure("JsonConverter", cmax)
      For i = 1 To cmax
        x = JsonConverter.ConvertToJson(timHallJSON)
      Next
    End With
    With stdPerformance.Measure("JsonBag", cmax)
      For i = 1 To cmax
        x = jsBag.JSON
      Next
    End With
    With stdPerformance.Measure("stdJSON", cmax)
      For i = 1 To cmax
        x = std.ToString
      Next
    End With
  End With
Results
JsonConverter: 4328 ms (432800µs per operation)
JsonBag: 10578 ms (1057800µs per operation)
stdJSON: 422 ms (42200µs per operation)

As we can see stdJSON is much better than the competition here, so at least we have something right. I think this is largely because both JSONConverter and JsonBag commonly use str = left(str, len(str)-1) to handle trailing commas, which when dealing with huge strings is incredibly slow! Instead we prevent the trailing commas from being in the string in the first place. Perhaps a better solution however is leave the trailing commas alone, and trim our buffer by subtracting 1 from the buffer index after the last operation...

Next steps

Consider allowing trailing commas, and removing the commas just by subtracting 1 from the buffer index.

Lingua principale
VBA
Stelle
412
Fork
70
Merge medio
16h 10m
PR unite (30g)
3

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di sancarn/stdVBA

Tutte le issue di sancarn/stdVBA

Issue simili

Altre issue su Performance

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.