pquerna / ffjson

faster JSON serialization for Go
Apache License 2.0
2.96k stars 234 forks source link

Advice on fast vs slow types #23

Closed jgoodall closed 9 years ago

jgoodall commented 9 years ago

The Readme notes that speed improvements will "depending on the structure". What data types will see the most or least improvements?

pquerna commented 9 years ago

Pretty much all basic types and structs will hit the 2-3x performance gain. I'm always looking for real world examples to add to the built in benchmarks, so if you have a good example structure you can share that would be great.

Known areas of weakness:

Marshal:

Unmarshal:

klauspost commented 9 years ago

Also, it should be possible to string together multiple buf.WriteString:

    buf.WriteString(`{`)
    buf.WriteString(`"message":`)

Should be able to become:

    buf.WriteString(`{"message":`)

Nothing big, but it avoids: 2 function calls (I assume copy() is inlined), 1 buffer size check (in buf.grow), one re-slice (grow), 1 copy operation.

pquerna commented 9 years ago

@klauspost To do that consistently, I think I'd have to move to more of an AST-style representation and then have an optimization pass to merge WriteString calls.

klauspost commented 9 years ago

I think we have coverered the issues now in the documentation, so I will close this issue.