I have long thought about using HTTP content negotiation to skip expensive CODECs (i.e. JSON) and just exchange Erlang terms within our Erlang based cloud.
This weekend I finally got around to doing something about it. I created a project (github.com/vances/erlang-content-coding) with an example implementation and test suites.
There is definitely an improvement when you skip the CODEC and just use Erlang external term format (binary_to_term/1,2). The test suite for raw CODEC performance (ecc_demo_codec_SUITE) consistently supports that:
encode_json Encoded 240184 bytes in 2141us.
decode_json Decoded 240184 bytes in 270us.
encode_external Encoded 240625 bytes in 68us.
decode_external Decoded 240625 bytes in 121us.
The idea with content negotiation is to use the Accept-Encoding: header to advertise availability and Content-Encoding: to declare it’s use. This allows us to support native Erlang term exchange on any client or server, without impacting any other use cases. I implemented a test suite (ecc_demo_http_SUITE) with inets httpd/httpc which works but I’m still thinking about how to get meaningful performance metrics.
I’m considering authoring an IETF draft next to move towards getting an IANA registry assignment (erlang?).