Test/fix assertions for go127 - #17
Merged
Merged
Conversation
Before go1.27, the flate library could not produce a compressed string that fits into a Handle. That case was not covered in go1.26. Now some tests with extreme compressions ratios (e.g. 129 times "a") may be inlined, with the compressed string packed into the returned handle and zero arena consumption. Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
go1.27 rewrote compress/flate, which changed *which* encoding branch a
string lands in and made two latent bugs reachable. TestStoreAllocations
was failing on go1.27 as a result.
Two independent stdlib behaviour changes are at play:
- highly repetitive input now deflates below 9 bytes (129 x "a": 9 -> 6),
so it is inlined in the handle instead of going to the arena. That made
headerInlinedCompressedString reachable for the first time.
- incompressible input now falls back to a *stored* block at the default
level, so the output can be larger than the input (350 -> 357, where
go1.26 Huffman-coded it down to 251).
Fixes:
- ensureEmptyBuffer grew the caller scratch relative to its length rather
than its capacity, so passing a full `var buf [8]byte` as buf[:] asked
slices.Grow for len+size and reallocated every time. It now truncates
before growing; unpackASCII and unpackBlanks had open-coded copies of
the same bug and route through the helper.
- stack scratch arrays handed to a pooled reader or to the writer
interface escaped to the heap (5 sites flagged by -gcflags=-m). They now
borrow from poolOfBytes.
- putCompressedString sized its scratch at len(value); it now uses
compressBound(), which accounts for stored-block framing.
- putCompressedString keeps the raw bytes when DEFLATE does not shrink the
value, instead of spending more arena space AND an inflate on every read.
- minCompressedSize 9 -> 6, re-documented as a sizing heuristic rather
than the stdlib invariant it used to be. uncompressRatioHeuristic floors
on compressionThreshold+1, a far better bound for inlined payloads, and
getCompressedString no longer pre-sizes its result buffer, so a wrong
ratio guess can never cost a second allocation.
- uncompressStringReader returned a redeem closure capturing three
variables, which escaped on every call. It now returns an inflateSession
struct by value.
TestStoreAllocations keyed its expectations on the measured alloc count,
which could only fail by a wide margin. Expectations now derive from the
handle header, each subtest asserts which encoding was chosen, and a new
WriteTo group asserts that path is allocation-free.
Measured on go1.27: WriteTo 1 -> 0 allocs for inlined strings, inlined
ASCII and compressed values; AppendValueBytes 2 -> 0 for inlined-compressed;
Get 3 -> 1 for inlined-compressed.
Verified on go1.27.0 and go1.26.7 across the none/guards/poolsdebug/
writerguards build tags, plus -race and golangci-lint.
Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
doc: retire gocard badge chore: schedule dependabot twice a week Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
fredbi
force-pushed
the
test/fix-assertions-for-go127
branch
from
August 23, 2026 06:45
ef68b9c to
f208731
Compare
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (67.18%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #17 +/- ##
==========================================
+ Coverage 63.88% 69.19% +5.30%
==========================================
Files 90 90
Lines 9681 9681
==========================================
+ Hits 6185 6699 +514
+ Misses 2994 2973 -21
+ Partials 502 9 -493 ☔ View full report in Codecov by Harness. |
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change type
Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update
Short description
Fixes
Full description
Checklist