Skip to content

fix(bitops): Fetch only single byte for SETBIT operation#6745

Merged
mkaruza merged 7 commits intomainfrom
mkaruza/bitops-fix
Mar 1, 2026
Merged

fix(bitops): Fetch only single byte for SETBIT operation#6745
mkaruza merged 7 commits intomainfrom
mkaruza/bitops-fix

Conversation

@mkaruza
Copy link
Contributor

@mkaruza mkaruza commented Feb 26, 2026

Instead of retrieving complete object we can get single byte on which
SETBIT operates.

@mkaruza mkaruza requested review from Copilot, kostasrim and romange and removed request for Copilot February 26, 2026 14:29
Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 5 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Copilot AI review requested due to automatic review settings February 27, 2026 12:56
@mkaruza mkaruza changed the base branch from main to mkaruza/get-set-byte-compact-object February 27, 2026 12:57
@mkaruza mkaruza changed the title fix(bitops): Read only one byte with SETBIT fix(bitops): Fetch only single byte for SETBIT operation Feb 27, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GetByteAtIndex and SetByteAtIndex methods in CompactObj for efficient byte-level operations
  • Modified BitNewValue to 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

@mkaruza mkaruza force-pushed the mkaruza/bitops-fix branch 2 times, most recently from f187fb1 to cb9a95c Compare February 27, 2026 14:47
@mkaruza mkaruza force-pushed the mkaruza/get-set-byte-compact-object branch from f6401ef to 4dbb27f Compare February 27, 2026 21:08
Base automatically changed from mkaruza/get-set-byte-compact-object to main February 28, 2026 20:26
Copilot AI review requested due to automatic review settings February 28, 2026 20:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

@mkaruza mkaruza requested a review from romange February 28, 2026 21:15
Copy link
Collaborator

@romange romange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the inconsistencies.

mkaruza added 2 commits March 1, 2026 10:53
Instead of retrieving complete object we can get single byte on which
SETBIT operates.

Signed-off-by: mkaruza <mario@dragonflydb.io>
Copilot AI review requested due to automatic review settings March 1, 2026 10:54
@mkaruza mkaruza force-pushed the mkaruza/bitops-fix branch from e6ea53a to 0429336 Compare March 1, 2026 10:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment on lines +325 to +327
if (!success) {
updater_.post_updater.Run();
}
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Suggested change
if (!success) {
updater_.post_updater.Run();
}
DCHECK(success);

Copilot uses AI. Check for mistakes.
@Claude
Copy link
Contributor

Claude AI commented Mar 1, 2026

@romange I've opened a new pull request, #6770, to work on those changes. Once the pull request is ready, I'll request review from you.

* 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>
@mkaruza
Copy link
Contributor Author

mkaruza commented Mar 1, 2026

@copilot please remove ElementAccess::Size() function because it's not used anymore

Copy link
Contributor

Copilot AI commented Mar 1, 2026

@mkaruza I've opened a new pull request, #6773, to work on those changes. Once the pull request is ready, I'll request review from you.

* 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>
Copilot AI review requested due to automatic review settings March 1, 2026 14:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

romange
romange previously approved these changes Mar 1, 2026
Copilot AI review requested due to automatic review settings March 1, 2026 18:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@mkaruza mkaruza merged commit 9c5ab55 into main Mar 1, 2026
16 checks passed
@mkaruza mkaruza deleted the mkaruza/bitops-fix branch March 1, 2026 19:43
romange pushed a commit that referenced this pull request Mar 1, 2026
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>
romange pushed a commit that referenced this pull request Mar 1, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants