-
Notifications
You must be signed in to change notification settings - Fork 5.3k
compression: add brotli compressor and decompressor #12998
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
Changes from all commits
eb1f837
95e0251
6b8c9e4
7400a45
162eee4
f10361b
0a579d9
7166d94
9f5d5f3
b407c3a
d3d47fe
42ad0e9
3408206
dc8cf74
f139336
70a25ed
b4bd706
6f7393a
fc40f09
d6e47b0
4df3311
a26e102
8f3168f
f6ef155
4c8fcc0
aa6512c
296d81e
2b30376
53c047f
2bd7591
ea6c21a
d378c03
3b98400
40b204c
84f9703
5d62287
cd04f7c
d43d9a0
43d0b4a
032c9b5
9a2aa0e
23edfb8
29f4e54
6e88e7d
c7e316d
f2b5965
43327fa
f5e2200
2baf168
e8494ca
6e6e207
30cec33
4ffacc6
e6fb711
2101920
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
|
||
| load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_package( | ||
| deps = ["@com_github_cncf_udpa//udpa/annotations:pkg"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.extensions.compression.brotli.compressor.v3; | ||
|
|
||
| import "google/protobuf/wrappers.proto"; | ||
|
|
||
| import "udpa/annotations/status.proto"; | ||
| import "validate/validate.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.extensions.compression.brotli.compressor.v3"; | ||
| option java_outer_classname = "BrotliProto"; | ||
| option java_multiple_files = true; | ||
| option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
|
||
| // [#protodoc-title: Brotli Compressor] | ||
| // [#extension: envoy.compression.brotli.compressor] | ||
|
|
||
| // [#next-free-field: 7] | ||
| message Brotli { | ||
| enum EncoderMode { | ||
| DEFAULT = 0; | ||
| GENERIC = 1; | ||
| TEXT = 2; | ||
| FONT = 3; | ||
| } | ||
|
|
||
| // Value from 0 to 11 that controls the main compression speed-density lever. | ||
| // The higher quality, the slower compression. The default value is 3. | ||
| google.protobuf.UInt32Value quality = 1 [(validate.rules).uint32 = {lte: 11}]; | ||
|
|
||
| // A value used to tune encoder for specific input. For more information about modes, | ||
| // please refer to brotli manual: https://brotli.org/encode.html#aa6f | ||
| // This field will be set to "DEFAULT" if not specified. | ||
| EncoderMode encoder_mode = 2 [(validate.rules).enum = {defined_only: true}]; | ||
|
|
||
| // Value from 10 to 24 that represents the base two logarithmic of the compressor's window size. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These defaults may be a bit too compression-ratio optimized:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. Saner defaults wouldn't harm definitely. What would be the best choices for your use cases?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at cloudflare they use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Updated the defaults. |
||
| // Larger window results in better compression at the expense of memory usage. The default is 18. | ||
| // For more details about this parameter, please refer to brotli manual: | ||
| // https://brotli.org/encode.html#a9a8 | ||
| google.protobuf.UInt32Value window_bits = 3 [(validate.rules).uint32 = {lte: 24 gte: 10}]; | ||
|
|
||
| // Value from 16 to 24 that represents the base two logarithmic of the compressor's input block | ||
| // size. Larger input block results in better compression at the expense of memory usage. The | ||
| // default is 24. For more details about this parameter, please refer to brotli manual: | ||
| // https://brotli.org/encode.html#a9a8 | ||
| google.protobuf.UInt32Value input_block_bits = 4 [(validate.rules).uint32 = {lte: 24 gte: 16}]; | ||
|
|
||
| // Value for compressor's next output buffer. If not set, defaults to 4096. | ||
| google.protobuf.UInt32Value chunk_size = 5 [(validate.rules).uint32 = {lte: 65536 gte: 4096}]; | ||
|
|
||
| // If true, disables "literal context modeling" format feature. | ||
| // This flag is a "decoding-speed vs compression ratio" trade-off. | ||
| bool disable_literal_context_modeling = 6; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
|
||
| load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_package( | ||
| deps = ["@com_github_cncf_udpa//udpa/annotations:pkg"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.extensions.compression.brotli.decompressor.v3; | ||
|
|
||
| import "google/protobuf/wrappers.proto"; | ||
|
|
||
| import "udpa/annotations/status.proto"; | ||
| import "validate/validate.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.extensions.compression.brotli.decompressor.v3"; | ||
| option java_outer_classname = "BrotliProto"; | ||
| option java_multiple_files = true; | ||
| option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
|
||
| // [#protodoc-title: Brotli Decompressor] | ||
| // [#extension: envoy.compression.brotli.decompressor] | ||
|
|
||
| message Brotli { | ||
| // If true, disables "canny" ring buffer allocation strategy. | ||
| // Ring buffer is allocated according to window size, despite the real size of the content. | ||
| bool disable_ring_buffer_reallocation = 1; | ||
|
|
||
| // Value for decompressor's next output buffer. If not set, defaults to 4096. | ||
| google.protobuf.UInt32Value chunk_size = 2 [(validate.rules).uint32 = {lte: 65536 gte: 4096}]; | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_extension_package", | ||
| ) | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| envoy_extension_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "brotli_base_lib", | ||
| srcs = ["base.cc"], | ||
| hdrs = ["base.h"], | ||
| deps = [ | ||
| "//source/common/buffer:buffer_lib", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include "extensions/compression/brotli/common/base.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Compression { | ||
| namespace Brotli { | ||
| namespace Common { | ||
|
|
||
| BrotliContext::BrotliContext(const uint32_t chunk_size) | ||
| : chunk_size_{chunk_size}, chunk_ptr_{std::make_unique<uint8_t[]>(chunk_size)}, next_in_{}, | ||
| next_out_{chunk_ptr_.get()}, avail_in_{0}, avail_out_{chunk_size} {} | ||
|
|
||
| void BrotliContext::updateOutput(Buffer::Instance& output_buffer) { | ||
| if (avail_out_ == 0) { | ||
| output_buffer.add(static_cast<void*>(chunk_ptr_.get()), chunk_size_); | ||
| resetOut(); | ||
| } | ||
| } | ||
|
|
||
| void BrotliContext::finalizeOutput(Buffer::Instance& output_buffer) { | ||
| const size_t n_output = chunk_size_ - avail_out_; | ||
| if (n_output > 0) { | ||
| output_buffer.add(static_cast<void*>(chunk_ptr_.get()), n_output); | ||
| } | ||
| } | ||
|
|
||
| void BrotliContext::resetOut() { | ||
| avail_out_ = chunk_size_; | ||
| next_out_ = chunk_ptr_.get(); | ||
| } | ||
|
|
||
| } // namespace Common | ||
| } // namespace Brotli | ||
| } // namespace Compression | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do these come from? How will users decide which to use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, you comment below on this.