aws / aws-sdk-java-v2

The official AWS SDK for Java - Version 2
Apache License 2.0
2.2k stars 853 forks source link

Sugmanue/rpcv2 improve cbor performance 04 #5564

Closed sugmanue closed 2 months ago

sugmanue commented 2 months ago

Motivation and Context

Improvement to the lookup performance of marshallers and traits.

Both traits and marshalling types are open classes but with well known, finite, and, statically defined instances. We can improve the performance of the lookups of these values by enumerating them using an enum and associating the enum values to the concrete types, and then using a two level lookup: the fast level 1 uses the an enum map and the associate enumeration value as key, while the l2 uses a regular map with the values as keys as they are. This change improves not only RPCv2, but all the other protocols as well.

This change aims to reduce, or remove the hump highlighted in the flamegraph below

before-highligthed

Before

Benchmark                              (protocol)  (size)  Mode  Cnt      Score     Error  Units
JsonMarshallerBenchmark.unmarshall  smithy-rpc-v2   small  avgt    5   3415.127 ±  64.585  ns/op
JsonMarshallerBenchmark.unmarshall  smithy-rpc-v2  medium  avgt    5   5668.994 ±  16.272  ns/op
JsonMarshallerBenchmark.unmarshall  smithy-rpc-v2     big  avgt    5  19475.973 ± 133.802  ns/op
JsonMarshallerBenchmark.unmarshall       aws-json   small  avgt    5  10150.744 ±  28.942  ns/op
JsonMarshallerBenchmark.unmarshall       aws-json  medium  avgt    5  21037.573 ± 139.545  ns/op
JsonMarshallerBenchmark.unmarshall       aws-json     big  avgt    5  86466.945 ± 709.876  ns/op

And zoomed in flamegraph

before-enum-map

After

Benchmark                              (protocol)  (size)  Mode  Cnt      Score      Error  Units
JsonMarshallerBenchmark.unmarshall  smithy-rpc-v2   small  avgt    5   3166.243 ±  151.799  ns/op
JsonMarshallerBenchmark.unmarshall  smithy-rpc-v2  medium  avgt    5   5349.115 ±  172.858  ns/op
JsonMarshallerBenchmark.unmarshall  smithy-rpc-v2     big  avgt    5  17517.889 ±   41.898  ns/op
JsonMarshallerBenchmark.unmarshall       aws-json   small  avgt    5  10178.752 ±  167.762  ns/op
JsonMarshallerBenchmark.unmarshall       aws-json  medium  avgt    5  20440.322 ±  223.031  ns/op
JsonMarshallerBenchmark.unmarshall       aws-json     big  avgt    5  83252.862 ± 1159.517  ns/op

And zoomed in flamegraph

after-enum-map

Full flamegraph after this change

after-full

Modifications

Testing

Screenshots (if appropriate)

Types of changes

Checklist

License

sonarcloud[bot] commented 2 months ago

Quality Gate Failed Quality Gate failed

Failed conditions
49.3% Coverage on New Code (required ≥ 80%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint