You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's no reason to use JSON here, as the hash is only used internally. As long the input properly represents our targetConfig struct as []byte, any encoding works. gob may be a viable, more efficient alternative.
While the change is simple, we would, however, want to ensure that we have a unit test in place to confirm that hash generation results in the same value for identical configs and different values for different config, and run a one-off performance benchmark with a range of targetConfig sizes.
The text was updated successfully, but these errors were encountered:
gob performs a lot of memory allocations which causes worse performance than json
using github.com/goccy/go-json yields a 50% improvement in time: from 31036 ns/op to 20576 ns/op with similar allocations and amount of memory allocated
github.com/mitchellh/hashstructure also causes a lot of memory allocations (probably because of all the reflection used?)
our best bet seems to be gojson with bytes.Buffer pooling which uses the same amount of time to complete but with 50% of memory allocated: from 11174 B/op to 5830 B/op
From some flame graph analysis, we spend a lot of time doing JSON operations. Most of these are unavoidable because the Kong admin API speaks JSON, but we spend a non-insignificant amount of time encoding a hash input at https://github.com/Kong/kubernetes-ingress-controller/blob/v2.2.1/internal/dataplane/deckgen/deckgen.go#L21
There's no reason to use JSON here, as the hash is only used internally. As long the input properly represents our targetConfig struct as
[]byte
, any encoding works. gob may be a viable, more efficient alternative.While the change is simple, we would, however, want to ensure that we have a unit test in place to confirm that hash generation results in the same value for identical configs and different values for different config, and run a one-off performance benchmark with a range of targetConfig sizes.
The text was updated successfully, but these errors were encountered: