guregu / dynamo

expressive DynamoDB library for Go
Other
1.3k stars 179 forks source link

Optimize encoding #224

Closed guregu closed 10 months ago

guregu commented 10 months ago

Reworked the unmarshaling system, resulting in around a 1.5x speedup and less allocations. Still need to test it a bit more but it should work the same as the old way without any breaking changes. I will look at marshaling as well, but haven't gotten to it yet.

Before:

BenchmarkDecodeVeryComplex-12    239828         4363 ns/op        4324 B/op    58 allocs/op
BenchmarkDecodeSimple-12        3366724        351.5 ns/op         448 B/op     6 allocs/op

After:

BenchmarkDecodeVeryComplex-12    353025         2985 ns/op        1597 B/op      28 allocs/op
BenchmarkDecodeSimple-12         5403024       209.7 ns/op          40 B/op       3 allocs/op
guregu commented 10 months ago

Almost done, just need to finish encoding and clean it up. Results so far:

Before:
BenchmarkEncodeVeryComplex-12     252729     4109 ns/op     5421 B/op         89 allocs/op
BenchmarkEncodeSimple-12         2548044    468.7 ns/op      688 B/op         12 allocs/op

After:
BenchmarkEncodeVeryComplex-12    491612        2363 ns/op   4712 B/op         50 allocs/op
BenchmarkEncodeSimple-12         3866780      277.6 ns/op    611 B/op          7 allocs/op
guregu commented 10 months ago

I'm happy with where this is now. I have been testing it on one of my sites and will merge in a few days.