Repository navigation
Commit bb1aba2
authored
### Rationale for this change
`GZipCodec::Init()` initializes compressor state and then immediately initializes decompressor state, which tears the compressor state down again. Compressor state is fairly expensive to initialize (the `deflateInit2` call allocates ~256KiB), so this is rather wasteful. A caller that wants to compress has to do it twice (because decompressor initialization throws it away), and a caller that only wants to decompress still has to do the compressor setup. Whatever the caller wants to do with the GZipCodec, this is pure waste.
### What changes are included in this PR?
`GZipCodec::Init()` now validates the compression level and window size without allocating codec state. Since all the compression and decompression methods have to check the mode anyway before doing any work, this is safe.
### Are these changes tested?
Largely relying on existing test coverage; the interesting part is that `InitCompressor()` validated the compression level internally, so this check has to be extracted. Split the unit test that covered this into a few separate cases to make it clearer.
### Are there any user-facing changes?
No.
### Was AI used for this PR?
Yes, both to find the issue and to fix it (Codex).
**PR code and description written by:**
- [X] Human (PR desc)
- [X] AI (code)
**Reviewed before submission by:**
- [X] Human
- [ ] AI
- [ ] Not reviewed
#
* GitHub Issue: #51308
Authored-by: Lorenz Hübschle <lorenz@firebolt.io>
Signed-off-by: Antoine Pitrou <antoine@python.org>
1 parent ab7a6af commit bb1aba2
2 files changed
Lines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
| 482 | + | |
482 | 483 | | |
483 | 484 | | |
484 | | - | |
| 485 | + | |
| 486 | + | |
485 | 487 | | |
486 | 488 | | |
487 | 489 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
497 | | - | |
498 | | - | |
499 | | - | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
500 | 500 | | |
501 | | - | |
| 501 | + | |
502 | 502 | | |
503 | 503 | | |
504 | 504 | | |
| |||
0 commit comments