fix(bitops): Fetch only single byte for SETBIT operation#6745
Conversation
6027966 to
9c2612a
Compare
There was a problem hiding this comment.
Pull request overview
This PR optimizes the SETBIT command to avoid reading and writing the entire string value when setting a single bit. Instead, it reads and writes only the affected byte when possible.
Changes:
- Added byte-level access functions for ASCII-packed strings (
ascii_pack_byte,ascii_unpack_byte) - Implemented
GetByteAtIndexandSetByteAtIndexmethods inCompactObjfor efficient byte-level operations - Modified
BitNewValueto use byte-level operations when the bit offset is within the existing string size
Reviewed changes
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/core/detail/bitpacking.h | Added declarations for ascii_pack_byte and ascii_unpack_byte functions |
| src/core/detail/bitpacking.cc | Implemented byte-level pack/unpack for ASCII-encoded strings |
| src/core/compact_object.h | Added GetByteAtIndex, SetByteAtIndex methods and DecodeByte in StrEncoding |
| src/core/compact_object.cc | Implemented byte-level access for all CompactObj string encodings |
| src/core/compact_object_test.cc | Added comprehensive tests for byte-level operations (AsciiPackByte, GetByteAtOffset, SetByteAtOffset) |
| src/server/bitops_family.cc | Modified BitNewValue to use byte-level operations; added ElementAccess wrappers |
f187fb1 to
cb9a95c
Compare
f6401ef to
4dbb27f
Compare
bd65fbf to
c489984
Compare
romange
left a comment
There was a problem hiding this comment.
Please fix the inconsistencies.
Instead of retrieving complete object we can get single byte on which SETBIT operates. Signed-off-by: mkaruza <mario@dragonflydb.io>
e6ea53a to
0429336
Compare
src/server/bitops_family.cc
Outdated
| if (!success) { | ||
| updater_.post_updater.Run(); | ||
| } |
There was a problem hiding this comment.
SetByteAtIndex runs post_updater.Run() only when success is false. Since success == false means the byte was not updated (typically out-of-bounds), running the post-updater here can incorrectly mark the key as updated without any actual mutation. Consider treating success == false as a programming error (e.g. DCHECK/LOG(DFATAL)) or handling the failure explicitly (e.g. extend+commit) instead of calling post_updater.Run().
| if (!success) { | |
| updater_.post_updater.Run(); | |
| } | |
| DCHECK(success); |
* Initial plan * test(bitops): Add test for SETBIT extending existing key Addresses feedback from code review to add test coverage for the scenario where SETBIT extends an existing key beyond its current length. Co-authored-by: romange <3674760+romange@users.noreply.github.com> --------- Co-authored-by: anthropic-code-agent[bot] <242468646+Claude@users.noreply.github.com> Co-authored-by: romange <3674760+romange@users.noreply.github.com>
|
@copilot please remove ElementAccess::Size() function because it's not used anymore |
* Initial plan * Remove unused ElementAccess::Size() method Co-authored-by: mkaruza <3676457+mkaruza@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mkaruza <3676457+mkaruza@users.noreply.github.com>
Optimizes the SETBIT command to avoid reading and writing the entire string value when setting a single bit. Instead, it reads and writes only the affected byte when possible. Signed-off-by: mkaruza <mario@dragonflydb.io>
Optimizes the SETBIT command to avoid reading and writing the entire string value when setting a single bit. Instead, it reads and writes only the affected byte when possible. Signed-off-by: mkaruza <mario@dragonflydb.io>
Instead of retrieving complete object we can get single byte on which
SETBIT operates.