Optimize RedisValue / reader logic by using canonical parser and new ShortBlob storage kind#3114
Merged
Conversation
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.
Historically, only explicit integer and boolean results from the server (i.e.
:42\r\nor#t\r\n) get special treatment - otherwise we just take thebyte[]snapshot, which is alloc heavy if we're dealing with small values (we don't mind allocating when necessary, and there'sLease<byte>APIs for heavy scenarios - but let's avoid allocations for high volume trivial scenarios).Example scenarios:
getorhgeton a value that contains a countergetorhgeton a value that contains a short text stringincrbyfloat(always returns$, even in RESP3)Here, we introduce a new storage type (internal layout of
RedisValue, packing 8 bytes into the overlapped/union field, and using a new sentinel that defines the size (so we don't lose any available payload bits).If the value is longer than 8 bytes, we also check whether it is likely a canonical number, meaning: a
longordoublethat round-trips cleanly without any ambiguity; in those cases we use the pre-existing raw storage.Result:
long,ulongordoublevaluesAs a side win: the
RedisLiteralsvalues now also check whether to use short-blob storage, which covers most of them.All the usual semantics are otherwise preserved.