andybalholm / brotli

Pure Go Brotli encoder and decoder
MIT License
612 stars 53 forks source link

Very slow compression performance #50

Open StarpTech opened 1 month ago

StarpTech commented 1 month ago

Hi, I use the module to compress 3MB HTML and Javascript. The response takes seconds ~1.8s. The variant without the brotli middleware takes ~20ms

Compression level: 6 (Default)

Machine: Mac M3 Max

andybalholm commented 1 month ago

How does the speed change if you adjust the compression level?

StarpTech commented 1 month ago

Even with 0 still significant.

andybalholm commented 1 month ago

It sounds like the issue is something other than the brotli compression itself. What brotli middleware are you using?

StarpTech commented 1 month ago

https://github.com/wundergraph/cosmo/blob/702552b6783334978b2f3f5754e165142f425ec7/router/core/graph_server.go#L203-L215

andybalholm commented 1 month ago

I don't know anything about that middleware, but you could try an encoder function that just returns w instead of creating a brotli Writer. The response won't be readable, but the performance will tell you whether the brotli encoding has anything to do with your performance issue…