-
Notifications
You must be signed in to change notification settings - Fork 407
(perf): OwnedValue
with buffer to reduce allocations in VDBE
#1320
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
Conversation
while end < bytes.len() && bytes[end].is_ascii_digit() { | ||
end += 1; | ||
pub fn cast_text_to_integer(value: &mut OwnedValue) { | ||
if let Some(text) = value.as_text() { |
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 these kind of things I tend to prefer
let Some(text) = value.as_text() else {
value.convert_to_integer();
return;
}
keeps the nesting in check
core/types.rs
Outdated
let bytes = value.as_bytes(); | ||
self.buffer.clear(); | ||
self.buffer.reserve(bytes.len()); | ||
self.buffer.extend_from_slice(bytes); |
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::extend_from_slice
already does reserve(bytes.len())
internally for T: Copy
:
https://github.com/rust-lang/rust/blob/master/library/alloc/src/vec/mod.rs#L2590-L2596
Storing integers on the heap looks problematic, is limbo becoming javascript? 😅
|
The idea is to reuse the memory of an OwnedValue for any type. If you replace a Text with an Integer it will drop the memory previously allocated for a string and we don't want that. Now thinking about it, we should probably not heap allocate on |
8076363
to
98d774d
Compare
take a mutable reference to `OwnedValue` to convert between types with mutation instead of allocating a new `OwnedValue`.
Made `exec_cast` in execute.rs to take `&mut OwnedValue` as input. Other functions could be made mutable in the future based on the feasibility.
`OwnedValue` with buffer.
`ValueType` contains both type information and carries values of Int, Float inside the variant. `OwnedValue` contains the buffer which contains the data for the types of `Text` and `Blob`
98d774d
to
b9600f7
Compare
This pull request has been marked as stale due to inactivity. It will be closed in 7 days if no further activity occurs. |
This pull request has been closed due to inactivity. Please feel free to reopen it if you have further updates. |
Closes: #1236
WIP: more to come.