Embed keys and hash fields as SDS type 5#1613
Merged
Merged
Conversation
Until now, these embedded strings were SDS type 8, becuase they were copied as-is from EMBSTR encoded string objects, which always use SDS type 8. This change allows them to be embedded as SDS type 5, saving two bytes. The implementation of embeddeding SDS strings in other structures is refactored. sdswrite() is a new function to create an SDS representation into a buffer provided by the caller, instead of allocating it. sdscopytobuffer() which just copied the layout of an existing sds is deleted. The DEBUG SDSLEN command output is changed slightly, to account for correct allocation sizes for embedded strings and not report the same memory twice. Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #1613 +/- ##
============================================
- Coverage 71.04% 71.03% -0.02%
============================================
Files 121 121
Lines 65174 65243 +69
============================================
+ Hits 46304 46343 +39
- Misses 18870 18900 +30
|
ranshid
reviewed
Feb 5, 2025
ranshid
left a comment
Member
There was a problem hiding this comment.
(Sorry it took me time to get to it, was very sick for a long period of time)
Overall LGTM!
Some small comments and/or questions.
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
ranshid
approved these changes
Feb 5, 2025
zuiderkwast
added a commit
that referenced
this pull request
Feb 6, 2025
Fixes the following test case which fails in builds with allocators that
don't have usable size:
```
*** [err]: Memory usage of embedded string value in tests/unit/type/string.tcl
Expected '40' to be less than or equal to '32' (context: type eval line 5 cmd {assert_lessthan_equal [r memory usage quux] 32} proc ::test)
```
With allocators like libc malloc that doesn't have usable size, zmalloc
stores an extra size field in the allocation. This makes the memory
usage 8 bytes larger than we expected in this test case. We can just
skip this check. It's not the main thing tested in this test case.
The failure was introduced in #1613.
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
xbasel
pushed a commit
to xbasel/valkey
that referenced
this pull request
Mar 27, 2025
Until now, these embedded strings were SDS type 8, because they were copied as-is from EMBSTR encoded string objects, which always use SDS type 8. This change allows them to be embedded as SDS type 5, saving two bytes. The implementation of embeddeding SDS strings in other structures is refactored. `sdswrite()` is a new function to create an SDS representation into a buffer provided by the caller. `sdscopytobuffer()`, which just copied the layout of an existing sds, is deleted. The DEBUG SDSLEN command output is changed slightly, to account for correct allocation sizes of embedded strings and not report the same memory twice. Fixes valkey-io#1567 --------- Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
xbasel
pushed a commit
to xbasel/valkey
that referenced
this pull request
Mar 27, 2025
Fixes the following test case which fails in builds with allocators that
don't have usable size:
```
*** [err]: Memory usage of embedded string value in tests/unit/type/string.tcl
Expected '40' to be less than or equal to '32' (context: type eval line 5 cmd {assert_lessthan_equal [r memory usage quux] 32} proc ::test)
```
With allocators like libc malloc that doesn't have usable size, zmalloc
stores an extra size field in the allocation. This makes the memory
usage 8 bytes larger than we expected in this test case. We can just
skip this check. It's not the main thing tested in this test case.
The failure was introduced in valkey-io#1613.
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
xbasel
pushed a commit
to xbasel/valkey
that referenced
this pull request
Mar 27, 2025
Until now, these embedded strings were SDS type 8, because they were copied as-is from EMBSTR encoded string objects, which always use SDS type 8. This change allows them to be embedded as SDS type 5, saving two bytes. The implementation of embeddeding SDS strings in other structures is refactored. `sdswrite()` is a new function to create an SDS representation into a buffer provided by the caller. `sdscopytobuffer()`, which just copied the layout of an existing sds, is deleted. The DEBUG SDSLEN command output is changed slightly, to account for correct allocation sizes of embedded strings and not report the same memory twice. Fixes valkey-io#1567 --------- Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
xbasel
pushed a commit
to xbasel/valkey
that referenced
this pull request
Mar 27, 2025
Fixes the following test case which fails in builds with allocators that
don't have usable size:
```
*** [err]: Memory usage of embedded string value in tests/unit/type/string.tcl
Expected '40' to be less than or equal to '32' (context: type eval line 5 cmd {assert_lessthan_equal [r memory usage quux] 32} proc ::test)
```
With allocators like libc malloc that doesn't have usable size, zmalloc
stores an extra size field in the allocation. This makes the memory
usage 8 bytes larger than we expected in this test case. We can just
skip this check. It's not the main thing tested in this test case.
The failure was introduced in valkey-io#1613.
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
murphyjacob4
pushed a commit
to enjoy-binbin/valkey
that referenced
this pull request
Apr 13, 2025
Until now, these embedded strings were SDS type 8, because they were copied as-is from EMBSTR encoded string objects, which always use SDS type 8. This change allows them to be embedded as SDS type 5, saving two bytes. The implementation of embeddeding SDS strings in other structures is refactored. `sdswrite()` is a new function to create an SDS representation into a buffer provided by the caller. `sdscopytobuffer()`, which just copied the layout of an existing sds, is deleted. The DEBUG SDSLEN command output is changed slightly, to account for correct allocation sizes of embedded strings and not report the same memory twice. Fixes valkey-io#1567 --------- Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
murphyjacob4
pushed a commit
to enjoy-binbin/valkey
that referenced
this pull request
Apr 13, 2025
Fixes the following test case which fails in builds with allocators that
don't have usable size:
```
*** [err]: Memory usage of embedded string value in tests/unit/type/string.tcl
Expected '40' to be less than or equal to '32' (context: type eval line 5 cmd {assert_lessthan_equal [r memory usage quux] 32} proc ::test)
```
With allocators like libc malloc that doesn't have usable size, zmalloc
stores an extra size field in the allocation. This makes the memory
usage 8 bytes larger than we expected in this test case. We can just
skip this check. It's not the main thing tested in this test case.
The failure was introduced in valkey-io#1613.
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
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.
Until now, these embedded strings were SDS type 8, because they were copied as-is from EMBSTR encoded string objects, which always use SDS type 8. This change allows them to be embedded as SDS type 5, saving two bytes.
The implementation of embeddeding SDS strings in other structures is refactored.
sdswrite()is a new function to create an SDS representation into a buffer provided by the caller.sdscopytobuffer(), which just copied the layout of an existing sds, is deleted.The DEBUG SDSLEN command output is changed slightly, to account for correct allocation sizes of embedded strings and not report the same memory twice.
Fixes #1567