1.82.0 (2026-05-14)
Full Changelog: v1.81.3...v1.82.0
Features
- client: optimize json encoder for internal types (7e861d5)
This pull request is managed by Stainless's GitHub App.
The semver version number is based on included commit messages. Alternatively, you can manually set the version number in the title of this pull request.
For a better experience, it is recommended to use either rebase-merge or squash-merge when merging this pull request.
🔗 Stainless website
📚 Read the docs
🙋 Reach out for help or questions
Greptile Summary
This release (v1.82.0) introduces a JSON encoding optimization for internal SDK types: a new WithSkipCompaction option bypasses the redundant appendCompact scan that was applied after every json.Marshaler call, reducing O(keys²) iteration cost on nested SDK structs.
internal/encoding/json:appendCompactsignature is widened from a plainescape boolto a fullencOptsstruct; a newopt.gofile adds theOptionfunctional-option pattern andWithSkipCompaction;RawMessage(which relied on the stdlib) is commented out fromstream.go.packages/param/encoder.go:MarshalWithExtrasandMarshalUnionnow forwardWithSkipCompaction(true)to the shim encoder when marshaling SDK types, trading JSON-validity re-scanning for performance.packages/param/encoder_test.go: 176 lines of new tests verify the optimization across compacted/non-compacted cases; theshimjson-marshalsub-test usest.Logfon mismatch (see inline comment).
Confidence Score: 4/5
Safe to merge — the optimization is scoped to SDK-internal types and all existing callers pass the correct argument, but the WithSkipCompaction API has a latent defect that warrants a follow-up fix.
The core optimization logic is sound and well-tested. The one real defect is that WithSkipCompaction(b bool) always enables the optimization regardless of the value of b, so a caller passing false would get the opposite behavior with no indication of the bug. Today every call site passes true, so there is no runtime breakage, but the public API is wrong and could confuse future callers.
internal/encoding/json/opt.go — the WithSkipCompaction bool parameter is dead code and should be fixed before the API surface hardens.
Important Files Changed
| Filename | Overview |
|---|---|
| internal/encoding/json/opt.go | New file introducing Option/WithSkipCompaction; the bool parameter to WithSkipCompaction is always ignored, so passing false still enables the optimization.
|
| internal/encoding/json/encode.go | Marshal gains variadic opts ...Option; options are applied before marshaling; marshalerEncoder/addrMarshalerEncoder now pass full encOpts to appendCompact.
|
| internal/encoding/json/indent.go | Signature of appendCompact widened from (escape bool) to (opts encOpts); Compact updated accordingly; logic is equivalent to before.
|
| internal/encoding/json/stream.go | RawMessage commented out (it depended on the stdlib encoding/json); only packages/param/param.go references it via the standard-library import, so no breakage.
|
| internal/encoding/json/time.go | Single-line update to pass opts instead of opts.escapeHTML to appendCompact, matching the updated signature.
|
| packages/param/encoder.go | MarshalWithExtras and MarshalUnion now pass WithSkipCompaction(true) when calling the shim encoder, enabling the new optimization for SDK types.
|
| packages/param/encoder_test.go | Comprehensive new tests for the compaction optimization; shimjson-marshal subtest uses t.Logf for assertion failures, so mismatches do not fail CI.
|
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["shimjson.Marshal(v, opts...)"] --> B["apply encOpts"]
B --> C["marshalerEncoder / addrMarshalerEncoder"]
C --> D["v.MarshalJSON() → raw bytes"]
D --> E{opts.skipCompaction?}
E -- true --> F["append raw bytes directly\n(no scan, no validation)"]
E -- false --> G["appendCompact\n(scan + remove whitespace + escape HTML)"]
F --> H["final JSON output"]
G --> H
style F fill:#d4edda,stroke:#28a745
style G fill:#fff3cd,stroke:#ffc107
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.