Skip to content

Conversation

@vyavdoshenko
Copy link
Contributor

@vyavdoshenko vyavdoshenko commented Nov 20, 2025

Closes: #6044

Add DenseSet::Shrink() to reduce the hash table size when sets/hashes have excess capacity after deletions.

  • DenseSet::Shrink() - relocates elements to a smaller bucket array
  • MEMORY SHRINK - command to shrink a specific key

Copy link
Contributor

@dranikpg dranikpg left a comment

Choose a reason for hiding this comment

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

It seems to me that all those internal calls to Delete() are now not safe anymore. The safeguards are not a substitute for actually reviewing the code around it and its usage

@BorysTheDev
Copy link
Contributor

@dranikpg I've already discussed with @vyavdoshenko all these problems; he rewrites all this logic.

@vyavdoshenko vyavdoshenko marked this pull request as draft November 21, 2025 09:12
@vyavdoshenko vyavdoshenko changed the title feat: implement DenseSet shrink with iterator safety [WIP] feat: implement DenseSet shrink with iterator safety Nov 21, 2025
@vyavdoshenko vyavdoshenko marked this pull request as ready for review November 25, 2025 10:59
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. 3 suggestions posted.

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

@vyavdoshenko vyavdoshenko force-pushed the bobik/shrink_dense_set branch from 038c970 to c23eba4 Compare December 1, 2025 14:42
Copy link
Contributor

@dranikpg dranikpg left a comment

Choose a reason for hiding this comment

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

After multiple rounds of review by Borys I don't have much comments 🙂 Please don't forget to set set_time (see comments)

Comment on lines +409 to +413
if (has_ttl && ObjExpireTime(obj) <= time_now_) {
ObjDelete(obj, true);
--size_;
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this will currently never happen because you never call set_time() from the SHRINK command, you can look at container_utils::GetStringMap for an example

<< CI{"LATENCY", CO::NOSCRIPT | CO::LOADING | CO::FAST, -2, 0, 0, acl::kLatency}.HFUNC(
Latency)
<< CI{"MEMORY", kMemOpts, -2, 0, 0, acl::kMemory}.HFUNC(Memory)
<< CI{"SHRINK", CO::WRITE | CO::FAST, 2, 1, 1, acl::kMemory}.HFUNC(Shrink)
Copy link
Contributor

Choose a reason for hiding this comment

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

haven't seen what it was before, but I assumed it has to be part of MEMORY. It won't be as easy to a transaction then, because you'll need to create one manually

continue;
}

uint32_t new_bid = BucketId(obj, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

based on the hash functon, it looks like 2*i and i are mapped to -> i. Not sure if its worth dcheck'ing or commenting, because the code looks more generic than it already is

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.

Add Shrink() to DenseSet

6 participants