Repository navigation
minimize duplicative JSON parsing while handling entries - #2880
Merged
Merged
Conversation
Signed-off-by: Bob Callaway <bcallaway@google.com>
Signed-off-by: Bob Callaway <bcallaway@google.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2880 +/- ##
===========================================
- Coverage 66.46% 27.53% -38.93%
===========================================
Files 92 191 +99
Lines 9258 20282 +11024
===========================================
- Hits 6153 5585 -568
- Misses 2359 13831 +11472
- Partials 746 866 +120
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Hayden-IO
approved these changes
Jul 10, 2026
stgrace
pushed a commit
to stgrace/rekor
that referenced
this pull request
Aug 22, 2026
* minmize duplicative JSON parsing Signed-off-by: Bob Callaway <bcallaway@google.com> * add license headers Signed-off-by: Bob Callaway <bcallaway@google.com> --------- Signed-off-by: Bob Callaway <bcallaway@google.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.
Motivation
CPU + heap-alloc profiles captured from a production rekor-server showed the JSON unmarshal of
ProposedEntryon theCreateLogEntryhandler dominating request cost:UnmarshalProposedEntry— 31 % of total CPU (cumulative)UnmarshalProposedEntry— 60 % of total alloc_space(*DSSE).UnmarshalJSONalone — 27.8 % of allocs (~594 MB in a 10 s trace)json.Decoder.refill— 42 % of alloc_space, driven by repeated 4 KB-growing buffers on multi-hundred-KB bodiesRoot cause is the polymorphic-unmarshal pattern go-swagger emits for a discriminated base type: the request body is decoded three times on the hot path:
io.ReadAll+ a sniff forkindUnmarshalJSONChange
Replace the polymorphic sniff-then-consumer-decode with a single JSON pass into a shim, then construct the concrete value directly from the shim.
This was done via overriding the swagger code-gen template rather than patching the generated code directly.
Because every
kind's Spec field is atype X anyalias, the resulting Spec (amap[string]anytree withUseNumber()semantics) is byte-for-byte identical to what the per-kind generatedUnmarshalJSONproduced.Performance Improvements from attached benchmarks
Small real payloads (~700 B – 1 KB)
Large real signed payloads — time (sec/op)
Large real signed payloads — allocated bytes (B/op)
Large real signed payloads — allocation count (allocs/op)