Skip to content

v1.2.0

Latest
Compare
Choose a tag to compare
@amitsuthar69 amitsuthar69 released this 23 Feb 13:12

Sending less bytes over the wire - LZ4 compression of response body.

I tested lz4 on a simple React project and found that compression significantly reduces the message size.

client logs:
❯ go run main.go http -p 3000
2025/02/23 15:30:40 Connected to remote server.
2025/02/23 15:30:40 Your public url: http://127.0.0.1:8888/pWWun4-PjRuWx
2025/02/23 15:30:44
HTML:
uncompressed: 1035bytes
compressed: 912 bytes
-----------------------------------
JS:
uncompressed: 389554bytes
compressed: 180138 bytes
-----------------------------------
CSS:
uncompressed: 20607bytes
compressed: 7912 bytes
server logs:
2025/02/23 15:30:39 Starting server on port  8888
2025/02/23 15:30:40 New client connection established with session ID: pWWun4-PjRuWx
2025/02/23 15:30:44 received compressed html: 912 bytes
2025/02/23 15:30:44 after uncompression: 1035 bytes
2025/02/23 15:30:44 received compressed js: 180138 bytes
2025/02/23 15:30:44 after uncompression: 389554 bytes
2025/02/23 15:30:44 received compressed css: 7912 bytes
2025/02/23 15:30:44 after uncompression: 20607 bytes

I chose LZ4 because it focuses on compression and decompression speed than compression ratio. And it works very well on repetitive data (in our case, msgpack encoded 1s and 0s).

On the client side:

raw response -> msgpack encode -> lz4 compress -> tunnel

On the server side:

tunnel -> lz4 decompress - > msgpack decode -> raw response