objconv icon indicating copy to clipboard operation
objconv copied to clipboard

[prototype] Add type-specific decoder code generator

Open tsholmes opened this issue 6 years ago • 0 comments

This adds a new objconvgen entrypoint that generates a optimized decoder for a specific type. Since the decoder doesn't need to use reflection and can return all results by-value, it attains a significant speedup from the generic parsing.

Since this is a prototype, I'd like to get some feedback on the approach I took. Any and all suggestions and feedback are welcome. This is a pretty big feature, so I'd like everyone to be on board with it.

Sample benchmark on a structure with strings, times, and nested arrays

BenchmarkDecodeCBOR-8                  200000          6431 ns/op          80 B/op           6 allocs/op
BenchmarkDecodeJSON-8                  200000          8607 ns/op          80 B/op           6 allocs/op
BenchmarkDecodeCBORGenerated-8         500000          3319 ns/op          48 B/op           5 allocs/op
BenchmarkDecodeJSONGenerated-8         300000          5425 ns/op          48 B/op           5 allocs/op

What's supported right now:

  • structures
  • arrays (not slices)
  • primitives
  • time.Time
  • aliased types
  • types in different packages

What's not supported right now:

  • slices
  • maps
  • time.Duration
  • []byte/[N]byte special case

What definitely needs to be done before this could be merged:

  • support json and objconv struct tags
  • write the output to a file and goimports/gofmt it
  • add tests on some generated code
  • add benchmarks on some generated code

What would be nice to clean up before this is merged:

  • remove dependence of generated code on github.com/segmentio/objconv/generate/util package

tsholmes avatar Apr 19 '18 01:04 tsholmes