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

Add config options for brotli.compress #10

Merged
merged 5 commits into from
Oct 7, 2020
Merged

Add config options for brotli.compress #10

merged 5 commits into from
Oct 7, 2020

Conversation

rpkyle
Copy link

@rpkyle rpkyle commented Oct 7, 2020

As of 48973cd, flask-compress now uses Brotli by default when the browser supports it.

While options to specify gzip compression parameters are available, the default compression setting is used when br is accepted; a quality level of 11 provides excellent compression, but is much slower than the previous default gzip setting.

This PR proposes to add support for specifying options passed to brotli.compress, in case application developers wish to specify a less aggressive compression setting. A couple basic tests mimicing those already present for gzip are also included.

Finally, the Brotli quality level default is changed to 4 from 11, which is a little more brisk (and comparable to the previous default, gzip level 6) when compressing on-the-fly.

@alexprengere
Copy link
Collaborator

alexprengere commented Oct 7, 2020

The PR looks good overall. A couple of remarks:

  • this adds quite a few parameters, for clarity I believe we should include the variable names with the algorithm they refer to, for example COMPRESSION_BR_MODE, COMPRESSION_BR_QUALITY, COMPRESS_BR_WINDOW, COMPRESSION_BR_BLOCK, because we already have COMPRESSION_LEVEL for gzip, and soon we may have similar parameters for deflate. This should make things clearer.
  • how do you justify the default values? Looking at the source code for Brotli, it looks like the default values are quality=11, lgwin=22, lgblock=0 (now that I looked, it is true that gzip default compression level here is 6, not the default from stdlib which is 9).
  • the test_quality_level is failing, I think this is because you rely on self.client_get which does not include brotli in the headers, so brotli is never used. You can fix this by relying on test_client directly (example)

@rpkyle
Copy link
Author

rpkyle commented Oct 7, 2020

The PR looks good overall. A couple of remarks:

this adds quite a few parameters, for clarity I believe we should include the variable names with the algorithm they refer to, for example COMPRESSION_BR_MODE, COMPRESSION_BR_QUALITY, COMPRESS_BR_WINDOW, COMPRESSION_BR_BLOCK, because we already have COMPRESSION_LEVEL for gzip, and soon we may have similar parameters for deflate. This should make things clearer.

@alexprengere Thanks, this makes a lot of sense. I've applied the requested edits in 7f04e85.

how do you justify the default values? Looking at the source code for Brotli, it looks like the default values are quality=11, lgwin=22, lgblock=0 (now that I looked, it is true that gzip default compression level here is 6, not the default from stdlib which is 9).

From prior experience, a Brotli quality level of 3 or 4 is comparable to what the typical default gzip compression offers in terms of compression time/file size. A default of 4 has also been recommended by others as a reasonable time/compression tradeoff for on-the-fly compression, e.g.

https://blogs.akamai.com/2016/02/understanding-brotlis-potential.html

the test_quality_level is failing, I think this is because you rely on self.client_get which does not include brotli in the headers, so brotli is never used. You can fix this by relying on test_client directly (example)

🙈 Thanks, I see exactly what you mean now. I believe this is fixed in 48b330a.

I've also contributed a stub for a CHANGELOG.md including the changes I've proposed, in case they are accepted.

@alexprengere alexprengere merged commit 5112e81 into colour-science:master Oct 7, 2020
@rpkyle rpkyle deleted the add-brotli-options branch October 7, 2020 14:31
@alexprengere
Copy link
Collaborator

Great work, thanks! For the record I pushed a077f93 to re-organize the README, and rename COMPRESS_BR_QUALITY to COMPRESS_BR_LEVEL, to be consistent with COMPRESS_LEVEL and COMPRESS_DEFLATE_LEVEL.

@rpkyle
Copy link
Author

rpkyle commented Oct 7, 2020

Thanks again @alexprengere!

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

Successfully merging this pull request may close these issues.

2 participants