Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content-Encoding: deflate is actually zlib #46

Closed
sschepens opened this issue Feb 5, 2016 · 8 comments
Closed

Content-Encoding: deflate is actually zlib #46

sschepens opened this issue Feb 5, 2016 · 8 comments

Comments

@sschepens
Copy link
Contributor

Had this issue with another library.
It's a little counter-intuitive, but Content-Encoding: deflate is actually not a simple flate stream, but a zlib one.
According to [Wikipedia](https://en.wikipedia.org/wiki/HTTP_compression:

deflate – compression based on the deflate algorithm (described in RFC 1951), wrapped inside the zlib data format (RFC 1950);

fasthttp currently uses flate package for handling deflated content, but should use zlib

Also, it would be great if fasthttp used: https://github.com/klauspost/compress as it provides optimized compression packages

@valyala
Copy link
Owner

valyala commented Feb 8, 2016

@sschepens , could you confirm that fasthttp now properly handles Content-Encoding: deflate?

@valyala
Copy link
Owner

valyala commented Feb 8, 2016

As for @klauspost 's compress library, I'll look into it later.

@klauspost
Copy link

AFAIR there are different opinions on what deflate means, which is why Content-Encoding: gzip is generally preferred.

Found a some information from Mark Adler:

[]...
However early Microsoft servers would incorrectly deliver raw deflate for "Deflate" (i.e. just RFC 1951 data without the zlib RFC 1950 wrapper). This caused problems, browsers had to try it both ways, and in the end it was simply more reliable to only use gzip.

The impact in bandwidth and execution time to use gzip instead of "Deflate" (zlib), is relatively small. So there we are and there it is likely to remain.

The difference is 12 more bytes for gzip and slightly more CPU time to calculate a CRC instead of an Adler-32.

CRC will actually be faster on AMD64, since there are assembler optimized routines (if you use my compression package), so the last point isn't valid for Go.

@sschepens
Copy link
Contributor Author

@klauspost I know gzip is usually preferred over deflate, but I use some services that only support deflate. I believe nowadays it's more common to have deflate as zlib than raw deflate, and according to standard should be zlib.

@valyala
Copy link
Owner

valyala commented Feb 9, 2016

@klauspost , are there chances for the integration of your compression performance improvements into standard Go library?

@klauspost
Copy link

@valyala - yes, I have just begun submitting the CLs, but it will of course not be out until 1.7.

Meanwhile, it can easily be integrated. There should be nothing more than an import change to use the current code, which is roughly 1.7x faster than the built-in, with no allocations if the Encoder is reused - which you appear to already do.

valyala added a commit that referenced this issue Feb 10, 2016
…rd compress/*, since it provides better performance on average
@valyala
Copy link
Owner

valyala commented Feb 10, 2016

Substituted standard compress library with https://github.com/klauspost/compress

@valyala valyala closed this as completed Feb 10, 2016
@sschepens
Copy link
Contributor Author

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants