Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
- [ ] (minor) rename keys to ids in `LeaseEntry`, or actually put keys in there. either way
- [X] (minor) make `add_available_item_from_parts` wrap `add_available_items_from_parts`, not the other way around
- [ ] (minor) use a mockable clock when generating uuidv7s
- [ ] (perf) reduce unnecessary allocs, such as when copying data or allocating buffers. some is called out in code comments
- [X] (perf) reduce unnecessary allocs, such as when copying data or allocating buffers. some is called out in code comments
- [ ] (perf) sort the keys in `LeaseEntry` so we can do bsearch on them
- [ ] (major) ensure `extend` doesnt create multiple index entries for the same lease.
- [ ] (perf) add lease expiry index key to `LeaseEntry` so we don't have to do scans to find it when extending
Expand Down
13 changes: 4 additions & 9 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ impl crate::protocol::queue::Server for Server {

// Generate ids upfront and copy request data into owned memory so we can move
// it into a blocking task (capnp readers are not Send).
let ids: Vec<Vec<u8>> = items
let ids: Vec<[u8; 16]> = items
.iter()
.map(|_| uuid::Uuid::now_v7().as_bytes().to_vec())
.map(|_| uuid::Uuid::now_v7().into_bytes())
.collect();

let items_owned = items
Expand All @@ -135,8 +135,6 @@ impl crate::protocol::queue::Server for Server {

let storage = Arc::clone(&self.storage);
let notify = Arc::clone(&self.notify);
let ids_for_resp = ids.clone();

Promise::from_future(async move {
// Offload RocksDB work to the blocking thread pool.
let iter = ids
Expand All @@ -150,11 +148,8 @@ impl crate::protocol::queue::Server for Server {
}

// Build the response on the RPC thread.
let mut ids_builder = results
.get()
.init_resp()
.init_ids(ids_for_resp.len() as u32);
for (i, id) in ids_for_resp.iter().enumerate() {
let mut ids_builder = results.get().init_resp().init_ids(ids.len() as u32);
for (i, id) in ids.iter().enumerate() {
ids_builder.set(i as u32, id);
}
Ok(())
Expand Down
9 changes: 4 additions & 5 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,10 @@ impl Storage {

// Build the lease entry.
let lease_entry = build_lease_entry_message(lease_validity_secs, &polled_items)?;
let mut lease_entry_bs = Vec::with_capacity(lease_entry.size_in_words() * 8); // TODO: avoid allocation
serialize::write_message(&mut lease_entry_bs, &lease_entry)?;

let mut lease_buf = Vec::with_capacity(lease_entry.size_in_words() * 8);
serialize::write_message(&mut lease_buf, &lease_entry)?;
// Write the lease entry and its expiry index
txn.put(lease_key.as_ref(), &lease_entry_bs)?;
txn.put(lease_key.as_ref(), &lease_buf)?;
txn.put(lease_expiry_index_key.as_ref(), lease_key.as_ref())?;

drop(snapshot);
Expand Down Expand Up @@ -343,7 +342,7 @@ impl Storage {
out_keys.set(new_idx as u32, k);
new_idx += 1;
}
let mut buf = Vec::with_capacity(msg.size_in_words() * 8); // TODO: reduce allocs
let mut buf = Vec::with_capacity(msg.size_in_words() * 8);
serialize::write_message(&mut buf, &msg)?;
txn.put(lease_key.as_ref(), &buf)?;
}
Expand Down