Skip to content
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

chore: add defrag logic for sets #3833

Merged
merged 3 commits into from
Oct 2, 2024
Merged

chore: add defrag logic for sets #3833

merged 3 commits into from
Oct 2, 2024

Conversation

kostasrim
Copy link
Contributor

@kostasrim kostasrim commented Sep 30, 2024

This PR adds defragmentation logic for sets.

  • add defrag logic for sets
  • add small test

partially resolves #3822 [1/2]

@kostasrim kostasrim self-assigned this Sep 30, 2024
Comment on lines +166 to +168
const size_t blob_len = intsetBlobLen(is);
intset* replacement = (intset*)zmalloc(blob_len);
memcpy(replacement, is, blob_len);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is based on my understanding of how intset is implemented. I could be wrong.

  1. I can test this locally that memcpy works so we don't run into trouble
  2. Are there any tests that hit this path @adiholden

@kostasrim kostasrim requested a review from adiholden September 30, 2024 14:07
return {is, false};

const size_t blob_len = intsetBlobLen(is);
intset* replacement = (intset*)zmalloc(blob_len);
Copy link
Collaborator

Choose a reason for hiding this comment

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

we are allocating here another set with same size, but what if this set is very big? it can cause spike in rss.
for listpack its ok because we use it for small hsets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Imo I thought the exact same thing but we do the same for other DefragLogic. Maybe we can do this as an improvement for a future PR? That is, do not Defrag relateively big data structures ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

what other defrag logic will ? as I wrote for listpack it is not risk because it is limited in size,
ReallocIfNeeded in StrMap is itereating on all elements so we are not allocating twice the size of the entire map right? regarding string type reallocation I dont think thats an issue because I dont think uses use huge strings thats probably not a real use case

Copy link
Contributor Author

@kostasrim kostasrim Oct 1, 2024

Choose a reason for hiding this comment

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

ReallocIfNeeded in StrMap is itereating on all elements so we are not allocating twice the size of the entire map right?

True

Intsets

We have a limit on our side at 256 elements so I guess it should be fine. We also serialize a string to long, so I guess no more than 8 bytes per entry. In total we are looking at 256 * 8 bytes which is not a lot 🤷

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh inset is also limited with number of elements that in this case there is no issue

@kostasrim kostasrim merged commit a3abf41 into main Oct 2, 2024
9 checks passed
@kostasrim kostasrim deleted the kpr4 branch October 2, 2024 07:00
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.

Implement defragmentation for OBJ_ZSET and OBJ_SET
2 participants