-
Notifications
You must be signed in to change notification settings - Fork 0
reduce attr bitset memory #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
Reviewer's GuideRework 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 mappingerDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| inner_id = static_cast<int16_t>(bitsets_.size()); | ||
| bitset_map_[id] = inner_id; | ||
| bitsets_.emplace_back( |
There was a problem hiding this comment.
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.
|
@sourcery-ai review |
There was a problem hiding this 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| inner_id = static_cast<int16_t>(bitsets_.size()); | ||
| bitset_map_[id] = inner_id; | ||
| bitsets_.emplace_back( |
There was a problem hiding this comment.
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.
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 ☂️ |
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: