-
Notifications
You must be signed in to change notification settings - Fork 36
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
Brotli Defaults #121
Comments
better default values would be cool, at least in the readme |
I think we should have a v6.0.0 release with default Brotli encoding options. Otherwise I am guessing that 99% of use cases in Koa will suffer from the poor performance due to Node defaults. Where/how might I put in default values for Edit: People also don't always read the README, they just install and plug in the middleware and think it has sensible defaults. The Node defaults aren't sensible enough for Koa so probably should set our own. |
@niftylettuce Looks good to me. Some notes:
This brings us to a scenario when we may want to fine-tune compression depending on a type of payload, or its size. If it would be up to me, I would implement it using my two favorite techniques:
These techniques bring the following benefits:
|
@uhop this would be incredible. might you be able to open a PR for it? |
Will do tomorrow. |
I agree that koa-compress should not use the default brotli compression level (11). The performance is just terrible. For comparison, with a 12MB json file (real world data): BROTLI GZIP From this very limited test, one might select L9 as a reasonable default. Performance slows by 10x by selecting L10! |
In prod I use 5 or 7 (I don't recall how or why I arrived to these values). According to your tests, it is possible to do as well as gzip-9 with br-4 yet be faster than gzip-4. |
5 is a sensible setting. I plotted Level against compression % and time. The results are informative. Obviously results will differ with different data. The sample here is a 3MB JSON file. Note: Level 10 & 11 go way off the end of the chart. I just ignore them as not useful for realtime compression. |
@uhop I like your suggested changes to allow more flexibility. I agree with @niftylettuce that it would be a good idea for koa-compress to specify it's own default for brotli, to give reasonable out of the box performance. I'm thinking Brotli 5 may be the best all-round default. You could also make an argument for Brotli 9. More analysis here. |
i'm thinking a that gets deep-merged with options on initialization |
The current default compression leads to absolutely terrible performance. This default high compression option just made our initial page load 10x longer then necessary (we have a 1.2mb resource that includes the content for the entire website). Setting the compression level to 7 decreased initial page load from 4.6 secs to 0.4s. |
3d205cd didn't actually fix the default compression issue described in koajs#121 because the zlib format expects quality to be inside [an option called `params`](https://nodejs.org/api/zlib.html#class-brotlioptions)
* fix: correct brotli options format 3d205cd didn't actually fix the default compression issue described in #121 because the zlib format expects quality to be inside [an option called `params`](https://nodejs.org/api/zlib.html#class-brotlioptions) * tests: update defaults test * chore: remove trailing whitespace
For future viewers, maybe any params it's not suitable for you. Because brotli compression ratio is depend your data. This little snippet may usefull for understanding, which settings is best. https://gist.github.com/mrtcmn/6f8301a41c26cffaaccbf7ed078c7221 |
@uhop curious your opinion on this - I had to do the following to make compression work fast for https://forwardemail.net:
https://github.com/ladjs/web/blob/6c2c09e5f78f403194883d169a4823dec73da743/index.js#L152-L159
The text was updated successfully, but these errors were encountered: