matrix-org / matrix-spec

The Matrix protocol specification
Apache License 2.0
197 stars 97 forks source link

Apply compression to JSON data for decrease C2S and S2S traffic #417

Open MurzNN opened 5 years ago

MurzNN commented 5 years ago

Seems at now Matrix messages in JSON format sent without compression. Will be good to apply compression to them, because JSON data have very good compression level: https://starbeamrainbowlabs.com/blog/article.php?article=posts/275-Compression-Comparison.html So applying compression will decrease S2S and C2S traffic more than 2x times, especially considering that m.message contain message text in 2 formats (plain + html).

MurzNN commented 5 years ago

We can apply compression on nginx level, but by default it compress only text/html data, as descibed here: http://omgitsmgp.com/2013/09/03/compressing-nginx-json-responses/

Simply including gzip on; in your Nginx configuration only compresses responses with the MIME type text/html. If Nginx is returning JSON data with a MIME type application/json, you can enable compression for these responses by doing:

So will be good to add json compression in recommended nginx setup docs for Synapse.

turt2live commented 5 years ago

This would be a concern of the implementation (ie: synapse) and not necessarily one of the spec. It's quite handy to have the server return the full JSON object during client development, in my opinion.

florianjacob commented 5 years ago

Combining TLS and compression? Take care to avoid making Matrix vulnerable to BREACH by design, then! :stuck_out_tongue_winking_eye: