Skip to content

Conversation

@LHT129
Copy link
Owner

@LHT129 LHT129 commented Jul 30, 2025

Summary by Sourcery

Compact bitset storage by mapping original IDs to a contiguous bitsets_ array, reducing memory usage and updating associated methods and serialization accordingly.

Enhancements:

  • Introduce bitset_map_ to compact bitset storage and eliminate null placeholders
  • Update GetOneBitset, SetNewCount, InsertValue, and serialization/deserialization to use the new mapping

Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
@sourcery-ai
Copy link

sourcery-ai bot commented Jul 30, 2025

Reviewer's Guide

Rework MultiBitsetManager to use a dense bitset vector plus a separate mapping for allocated bitsets, updating creation, access, and (de)serialization to reflect the new storage layout.

ER diagram for new MultiBitsetManager bitset mapping

erDiagram
    MULTIBITSETMANAGER {
        uint64 id
        int16 inner_id
    }
    BITSET {
        int16 inner_id
    }
    MULTIBITSETMANAGER ||--o{ BITSET : maps_to
    %% MULTIBITSETMANAGER.bitset_map_ maps external id to BITSET.inner_id
    %% BITSET is stored densely, only for allocated bitsets
Loading

File-Level Changes

Change Details Files
Introduce dense storage with external-to-internal mapping
  • Add bitset_map_ member to header
  • Initialize map in constructors and on count changes
  • Remove direct resizing of sparse bitsets_ vector
src/attr/multi_bitset_manager.h
src/attr/multi_bitset_manager.cpp
Refactor GetOneBitset to consult mapping
  • Lookup inner_id via bitset_map_[id]
  • Return nullptr if mapping is -1
src/attr/multi_bitset_manager.cpp
Change InsertValue to lazy-allocate into compact vector
  • Check map entry and assign new inner_id when -1
  • Update bitset_map_ and emplace new ComputableBitset into bitsets_
  • Use inner_id for subsequent Set calls
src/attr/multi_bitset_manager.cpp
Revamp Serialize to include mapping and vector size
  • Write out all bitset_map_ entries
  • Write bitsets_.size() before serializing each bitset
  • Remove presence flags for empty slots
src/attr/multi_bitset_manager.cpp
Update Deserialize to rebuild map and dense bitsets_
  • Read bitset_map_ entries after count
  • Read size, resize bitsets_, then allocate and deserialize each bitset
src/attr/multi_bitset_manager.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @LHT129 - I've reviewed your changes - here's some feedback:

  • Using int16_t for bitset_map_ indexes may overflow if you end up with more than 32K bitsets—consider using a larger integer type or adding safeguards.
  • When you shrink count_ via SetNewCount, orphaned bitsets remain in bitsets_; consider pruning or freeing them to avoid memory leaks and stale entries.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Using int16_t for bitset_map_ indexes may overflow if you end up with more than 32K bitsets—consider using a larger integer type or adding safeguards.
- When you shrink count_ via SetNewCount, orphaned bitsets remain in bitsets_; consider pruning or freeing them to avoid memory leaks and stale entries.

## Individual Comments

### Comment 1
<location> `src/attr/multi_bitset_manager.cpp:71` </location>
<code_context>
-            ComputableBitset::MakeRawInstance(this->bitset_type_, this->allocator_);
+    auto inner_id = bitset_map_[id];
+    if (inner_id == -1) {
+        inner_id = static_cast<int16_t>(bitsets_.size());
+        bitset_map_[id] = inner_id;
+        bitsets_.emplace_back(
+            ComputableBitset::MakeRawInstance(this->bitset_type_, this->allocator_));
     }
</code_context>

<issue_to_address>
Potential for int16_t overflow in inner_id assignment.

Casting bitsets_.size() to int16_t may overflow if the number of bitsets exceeds int16_t's range. Use a larger integer type or add an overflow check.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +71 to +73
inner_id = static_cast<int16_t>(bitsets_.size());
bitset_map_[id] = inner_id;
bitsets_.emplace_back(
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Potential for int16_t overflow in inner_id assignment.

Casting bitsets_.size() to int16_t may overflow if the number of bitsets exceeds int16_t's range. Use a larger integer type or add an overflow check.

@LHT129
Copy link
Owner Author

LHT129 commented Jul 30, 2025

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @LHT129 - I've reviewed your changes - here's some feedback:

  • Consider using a larger integer type (e.g. size_t or int64_t) for bitset_map_ entries instead of int16_t to avoid overflow when bitsets_.size() grows beyond 32767.
  • When SetNewCount is called with a smaller count, you may want to free or remove bitsets no longer referenced to prevent stale internal indices and potential memory leaks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider using a larger integer type (e.g. size_t or int64_t) for bitset_map_ entries instead of int16_t to avoid overflow when bitsets_.size() grows beyond 32767.
- When SetNewCount is called with a smaller count, you may want to free or remove bitsets no longer referenced to prevent stale internal indices and potential memory leaks.

## Individual Comments

### Comment 1
<location> `src/attr/multi_bitset_manager.cpp:71` </location>
<code_context>
-            ComputableBitset::MakeRawInstance(this->bitset_type_, this->allocator_);
+    auto inner_id = bitset_map_[id];
+    if (inner_id == -1) {
+        inner_id = static_cast<int16_t>(bitsets_.size());
+        bitset_map_[id] = inner_id;
+        bitsets_.emplace_back(
+            ComputableBitset::MakeRawInstance(this->bitset_type_, this->allocator_));
     }
</code_context>

<issue_to_address>
Potential for int16_t overflow if bitsets_ grows large.

If creating more than 32,767 bitsets is possible, switch to a larger integer type for bitset_map_ to prevent overflow issues.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +71 to +73
inner_id = static_cast<int16_t>(bitsets_.size());
bitset_map_[id] = inner_id;
bitsets_.emplace_back(
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Potential for int16_t overflow if bitsets_ grows large.

If creating more than 32,767 bitsets is possible, switch to a larger integer type for bitset_map_ to prevent overflow issues.

@codecov-commenter
Copy link

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

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.

3 participants