Skip to content

1.2.4

Compare
Choose a tag to compare
@ugorji ugorji released this 04 Feb 17:27
· 180 commits to master since this release

Release 1.2.4

This is a production release of go-codec.

This is a very important release, which focused on optimization across the board to
ensure that go-codec is the most performant library for popular encoding formats.

Optimizations across the board include:

  • optimization by eliding allocation where not necessary e.g.
    • when encoding non-addressable value with ptr receiver
    • map iteration/access
    • decoding floats
    • creating slices or sub-slices (removing temporary slice allocated on heap)
    • decoding map keys if both key and value kinds are scalars
    • decoding map values if value kind is a scalar
  • better reuse of pool'ed []byte(s)
  • leveraging mapXXX_fastXXX calls where possible
  • better inlining (where applicable) e.g. arrayStart, mapStart, etc
  • support complex numbers (where we treat complex numbers as floats with imaginary part = 0)
  • optimize encoding and decoding arrays, including using fast-paths for slices as applicable
  • use runtime's growslice algorithm when growing arrays for better performance
  • optimize nextValueBytes and swallow so they do not allocate when applicable e.g.
    do not allocate/copy bytes if swallow is called or you were decoding from a []byte (just return a sub-slice)
  • optimize isEmptyStruct to just compare if value == zero'es (instead of field by field),
    simulating comparing to zero value.

To guarantee better fairness in benchmarking, we did the following:

  • use common types in benchmarks and common methods to ensure fairness in benchmarks
  • run benchmarks with ZeroCopy=true and (MapValue|Interface|SliceElement)Reset = true,
    aligning with how other libraries operate by default

With these changes, we have reflection-based mode performing within 25% of codecgen,
with similar allocation numbers as codecgen. For example, encoding typically has just 1
allocation without codecgen (just as in codecgen).

This is the best release yet. Please try it out and share your experiences.