-
Notifications
You must be signed in to change notification settings - Fork 907
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 flush config options to Gzip and Brotli AsyncOutputStream impls #2027
base: v2
Are you sure you want to change the base?
Conversation
Will take a look at this soon. Note that compression flushing is a can of worms – Zlib has a number of different flush options of which Z_SYNC_FLUSH should be sane but I'll take another look at them. Brotli is peculiar about when it provides output that led to a hard-to-find bug while developing support for it here, the current implementation should work with or without additional flushing but I want to understand well how it will behave differently. |
Yep, the way this is set up the exact flush option can be specified as an option, making it possible for us to evaluate the different options. Please definitely do give this some careful thought. If the brotli implementation is sufficient as is, I'm happy dropping the changes to that as the problem we're looking to address immediately is largely with gzip compression. I just did the brotli changes to keep things symmetrical. I was going to update this PR to incorporate a deferred flush using |
77d13a7
to
4e796a9
Compare
4e796a9
to
b8d7856
Compare
LGTM – I reviewed the current implementation and the documentation for |
@fhanau :
That was intentional to give us some flexibility later to use one of the other flush flags if necessary. |
I think that's valid. From the comments in zlib.h it sounded to me like the other flags might be slightly more efficient in some cases and avoid some empty deflate blocks being written. It felt unlikely to be relevant for us though – Z_SYNC_FLUSH is the most widely used option and in cases where compression efficiency is important we will hopefully not be flushing excessively or not be using zlib in the first place... Not a big issue either way, this can go ahead as-is. |
I really think we need to be using |
To elaborate, it is quite common to have several write() calls invoked in rapid succession. When pumping from one stream to another, we usually tryRead() with |
@kentonv ... what is your recommendation on the best way to handle this with |
Probably something like...
At the start of a pump():
At the end of a pump():
|
BTW I think we can always use Z_SYNC_FLUSH. Let's not let clients choose the flag until we have a use case. I'm concerned some of the flush flags also require slightly different control flow around them, so letting people choose those flags won't actually work anyway. |
b8d7856
to
dad7526
Compare
Adds the ability to configure the per-write flush behavior for both
GzipAsyncOutputStream
andBrotliAsyncOutputStream
, keeping the current defaults in place.By default, these implementations will flush only when either
flush()
is explicitly called or their output buffers are full. This is the ideal behavior for optimal compression but can increase perceived latency of the stream. This PR adds options to both Gzip and Brotli implementations to customize the per-write flush setting to permit for frequent flushes.