-
-
Notifications
You must be signed in to change notification settings - Fork 1
Decompressor/Compressor pool #34
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #34 +/- ##
==========================================
- Coverage 94.55% 93.30% -1.25%
==========================================
Files 3 4 +1
Lines 202 269 +67
==========================================
+ Hits 191 251 +60
- Misses 11 18 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
// keep finishing stream until we don't get a buffer overflow | ||
while true { | ||
do { | ||
try lastBuffer.compressStream(to: &self.window, with: self.compressor, flush: .finish) | ||
try lastBuffer.compressStream(to: &self.window, with: compressor, flush: .finish) | ||
try await self.parentWriter.write(self.window) |
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.
If this write
fails, the allocation isn't freed. Can we use a non-copyable with a deinit to handle this instead? Or a class or something similar.
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.
Using AllocatedValue class to hold these.
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.
There's a bug still, I'd prefer not manually managing allocations.
We can also lend an allocation using |
Unfortunately the way ResponseBodyWriters work doesn't lend themselves to |
Yes I understand, but we can't pool these without managing the allocation of them. |
Add a pool of decompressors and compressors for both gzip and deflate. When middleware needs either it will use one in the pool if it exists otherwise it will allocate a new one. When freeing the compressor/decompressor it will pass it back to the pool if the pool hasn't already reached its maximum size.
This should reduce the amount of allocations made by zlib considerably