Optimize decoding CBOR byte string - #811
Merged
Merged
Conversation
This commit caches type checks to optimize decoding of CBOR byte string and CBOR text string. Previously, when decoding a CBOR byte string, fillByteString() checked if the destination type implements: - BinaryUnmarshaler, for default options - TextUnmarshaler, for non-default options Also, when decoding a CBOR text string, fillTextString() checked if the destination type implements TextUnmarshaler for a non-default option. This commit caches both checks in typeInfo, so the checks are done once per type.
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.
On a new benchmark decoding CBOR byte string to user-defined type with methods, this PR reduces decoding duration by up to 60%. 🚀 On existing benchmarks, this PR reduces decoding duration for CBOR byte string by up to 28% (depending on the data structure and values being decoded).
This PR optimizes decoding of CBOR byte string by:
BinaryUnmarshalerandTextUnmarshalerinterface checks off the hot pathapplyByteStringTextConversionfor default decoding optionsBenchmarks
Benchmark results for
Unmarshal()omit allocs/op and B/op because they are unchanged: