Skip to content

(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

Closed
wants to merge 9 commits into from

Conversation

krishvishal
Copy link
Contributor

Closes: #1236

WIP: more to come.

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() {
Copy link
Collaborator

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);
Copy link
Collaborator

@jussisaurio jussisaurio Apr 12, 2025

Choose a reason for hiding this comment

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

@ihorandrianov
Copy link
Contributor

ihorandrianov commented Apr 13, 2025

Storing integers on the heap looks problematic, is limbo becoming javascript? 😅
Should we think about something like

enum OwnedValue {
  BigData(Vec<u8>)
  SmallData([u8; 24]) // or any convenient size so we could fit small strings and integers there,
  Null
  }

@pereman2
Copy link
Collaborator

Storing integers on the heap looks problematic, is limbo becoming javascript? 😅 Should we think about something like

enum OwnedValue {
  BigData(Vec<u8>)
  SmallData([u8; 24]) // or any convenient size so we could fit small strings and integers there,
  Null
  }

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 int, float and null and have separate values for those like in an enum but keep the buffer alive in case we replace that register and those text and blob values would reference the internal buffer.

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.
`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`
@penberg
Copy link
Collaborator

penberg commented May 16, 2025

This pull request has been marked as stale due to inactivity. It will be closed in 7 days if no further activity occurs.

@penberg penberg added the Stale label May 16, 2025
@penberg
Copy link
Collaborator

penberg commented May 24, 2025

This pull request has been closed due to inactivity. Please feel free to reopen it if you have further updates.

@penberg penberg closed this May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve OwnedValue Register in vdbe allocations
5 participants