Skip to content

Commit

Permalink
Inline a few more tuple related things, +~5% throughput bench improve…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
rdaum committed Jan 7, 2024
1 parent de1dd9f commit 85d3a47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions crates/db/src/tuplebox/tuples/slotbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl SlotBox {
Ok(refs)
}

#[inline(always)]
pub(crate) fn page_for<'a>(&self, id: PageId) -> Result<SlottedPage<'a>, SlotBoxError> {
let inner = self.inner.lock().unwrap();
inner.page_for(id)
Expand All @@ -128,12 +129,14 @@ impl SlotBox {
page_handle.refcount(id.slot)
}

#[inline(always)]
pub fn upcount(&self, id: TupleId) -> Result<(), SlotBoxError> {
let inner = self.inner.lock().unwrap();
let page_handle = inner.page_for(id.page)?;
page_handle.upcount(id.slot)
}

#[inline(always)]
pub fn dncount(&self, id: TupleId) -> Result<(), SlotBoxError> {
let mut inner = self.inner.lock().unwrap();
let page_handle = inner.page_for(id.page)?;
Expand All @@ -143,6 +146,7 @@ impl SlotBox {
Ok(())
}

#[inline(always)]
pub fn get(&self, id: TupleId) -> Result<Pin<&[u8]>, SlotBoxError> {
let inner = self.inner.lock().unwrap();
let page_handle = inner.page_for(id.page)?;
Expand Down Expand Up @@ -448,15 +452,18 @@ impl PageSpace {
}
}

#[inline(always)]
fn sort(&mut self) {
self.entries.sort()
}

#[inline(always)]
fn insert(&mut self, available: usize, bid: Bid) {
self.entries.push(encode(bid.0 as PageId, available));
self.sort();
}

#[inline(always)]
fn seek(&self, pid: PageId) -> Option<usize> {
self.entries
.iter()
Expand Down Expand Up @@ -529,6 +536,7 @@ impl PageSpace {
.map(|entry| (entry & 0xFFFF_FFFF_FFFF) as PageId)
}

#[inline(always)]
fn len(&self) -> usize {
self.entries.len()
}
Expand Down
6 changes: 5 additions & 1 deletion crates/db/src/tuplebox/tuples/slotted_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ impl<'a> PageWriteGuard<'a> {
sp.remove_slot(slot_id)
}

#[inline(always)]
pub fn upcount(&mut self, slot_id: SlotId) -> Result<(), SlotBoxError> {
let sp = SlottedPage {
base_address: self.base_address,
Expand All @@ -711,6 +712,7 @@ impl<'a> PageWriteGuard<'a> {
}

impl<'a> Drop for PageWriteGuard<'a> {
#[inline(always)]
fn drop(&mut self) {
let header = self.header_mut();
header.unlock_for_writes();
Expand All @@ -725,13 +727,14 @@ pub struct PageReadGuard<'a> {
}

impl<'a> PageReadGuard<'a> {
#[inline(always)]
fn header(&self) -> Pin<&SlottedPageHeader> {
let header_ptr = self.base_address as *const SlottedPageHeader;

unsafe { Pin::new_unchecked(&*header_ptr) }
}

#[inline]
#[inline(always)]
pub fn get_slot(&self, slot_id: SlotId) -> Result<Pin<&'a [u8]>, SlotBoxError> {
let sp = SlottedPage {
base_address: self.base_address as _,
Expand All @@ -743,6 +746,7 @@ impl<'a> PageReadGuard<'a> {
}

impl<'a> Drop for PageReadGuard<'a> {
#[inline(always)]
fn drop(&mut self) {
let header = self.header();
// Decrement the state by 2 to remove one read-lock.
Expand Down

0 comments on commit 85d3a47

Please sign in to comment.