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

storage: use slice as variable for key_with_epoch #6069

Closed
Little-Wallace opened this issue Oct 27, 2022 · 4 comments
Closed

storage: use slice as variable for key_with_epoch #6069

Little-Wallace opened this issue Oct 27, 2022 · 4 comments
Assignees

Comments

@Little-Wallace
Copy link
Contributor

Little-Wallace commented Oct 27, 2022

Is your feature request related to a problem? Please describe.

If we pass an variable Vec<u8> we must re-allocate this key if the capacity of this vector is less than the sum length of user_key and epoch.
In most where we must convert slice to Vec and then pass it to key_with_epoch, and it means that we would allocate memory twice.

Describe the solution you'd like

It is better to pass a slice and allocate the whole key in method key_with_epoch.

fn key_with_epoch(user_key: &[u8], epoch: HummockEpoch) -> Vec<u8> {

}

Describe alternatives you've considered

No response

Additional context

No response

@BugenZhao
Copy link
Member

FYI, we may use Buf::chain if we really care about the allocation and copying. 🤔
https://docs.rs/bytes/latest/bytes/trait.Buf.html#method.chain

@Little-Wallace
Copy link
Contributor Author

It seems to be complex...

@Little-Wallace
Copy link
Contributor Author

FYI, we may use Buf::chain if we really care about the allocation and copying. 🤔 https://docs.rs/bytes/latest/bytes/trait.Buf.html#method.chain

key_with_epoch is also not convenient for unit test

@hzxa21
Copy link
Collaborator

hzxa21 commented Nov 22, 2022

After #6130, key_with_epoch is only used in tests so I think we can close this issue.

@hzxa21 hzxa21 closed this as completed Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants