-
Notifications
You must be signed in to change notification settings - Fork 157
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
reduce memory allocation when create ReadOptions object #69
Conversation
@@ -158,7 +158,7 @@ impl UnsafeSnap { | |||
|
|||
pub struct ReadOptions { | |||
inner: *mut DBReadOptions, | |||
upper_bound: Vec<u8>, | |||
upper_bound: Option<Vec<u8>>, |
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.
better use Option<Box<Vec<T>>>
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.
For what reason?
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.
smaller size.
Option<Vec>
-> 4 usize (a pointer, a length, a capacity, a tag)Box<Vec<_>>
-> 1 usize (a pointer)Option<Box<Vec>>
-> 1 usize (a pointer, since Box impls NonZero optimization)
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.
Option<Box<Vec<T>>>
is used in rust implementation, called ThinVec<T>
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.
Vec
points a continuous memory on heap already, I think it's ridiculous to use Box
again, which will allocate again.
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.
does it really cause the memory problem?
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.
@siddontang no
@BusyJay this is the optimization for a normally-empty Vec. not ridiculous or something.
I don't think |
struct crocksdb_readoptions_t {
ReadOptions rep;
Slice upper_bound; // stack variable to set pointer to in ReadOptions
};
better use singleton pattern? |
A better way to do this is add a new C ABI to support snapshot read (event support upper bound). In that way, |
Wraps Options into Cow. export copy ctor. |
In most cases the |
CI failed |
So why replacing |
Close this pr since |
No description provided.