Skip to content

Commit bfe88b8

Browse files
Add #[inline] hints to hot path functions (#8260)
## Summary This PR adds `#[inline]` hints to a collection of small, frequently-called functions across the codebase to improve performance. These are primarily simple wrapper methods, trait implementations, and utility functions that benefit from inlining to reduce function call overhead. These are all candidates for inlining because they are: 1. Small wrapper functions with minimal logic 2. Called frequently in hot paths (e.g., binary search, array access) 3. Generic or trait methods where inlining enables better monomorphization 4. Simple accessors and type checks
1 parent e484daf commit bfe88b8

8 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎vortex-array/src/array/erased.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,16 +390,19 @@ impl ArrayRef {
390390
}
391391

392392
/// Does the array match the given matcher.
393+
#[inline]
393394
pub fn is<M: Matcher>(&self) -> bool {
394395
M::matches(self)
395396
}
396397

397398
/// Returns the array downcast by the given matcher.
399+
#[inline]
398400
pub fn as_<M: Matcher>(&self) -> M::Match<'_> {
399401
self.as_opt::<M>().vortex_expect("Failed to downcast")
400402
}
401403

402404
/// Returns the array downcast by the given matcher.
405+
#[inline]
403406
pub fn as_opt<M: Matcher>(&self) -> Option<M::Match<'_>> {
404407
M::try_match(self)
405408
}
@@ -738,10 +741,12 @@ impl IntoArray for ArrayRef {
738741
impl<V: VTable> Matcher for V {
739742
type Match<'a> = ArrayView<'a, V>;
740743

744+
#[inline]
741745
fn matches(array: &ArrayRef) -> bool {
742746
array.0.data.as_any().is::<ArrayData<V>>()
743747
}
744748

749+
#[inline]
745750
fn try_match(array: &'_ ArrayRef) -> Option<ArrayView<'_, V>> {
746751
let inner = array.0.data.as_any().downcast_ref::<ArrayData<V>>()?;
747752
// # Safety checked by `downcast_ref`.

‎vortex-array/src/arrays/varbinview/compute/zip.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ fn push_range(
177177
}
178178
}
179179

180+
#[inline]
180181
fn push_view(
181182
view: BinaryView,
182183
buffer_lookup: &[u32],

‎vortex-array/src/buffer.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ impl BufferHandle {
249249
}
250250

251251
/// Downcast this handle as a handle to a host-resident buffer, or `None`.
252+
#[inline]
252253
pub fn as_host_opt(&self) -> Option<&ByteBuffer> {
253254
match &self.0 {
254255
Inner::Host(buffer) => Some(buffer),
@@ -266,6 +267,7 @@ impl BufferHandle {
266267

267268
/// A version of [`as_host_opt`][Self::as_host_opt] that panics if the allocation is
268269
/// not a host allocation.
270+
#[inline]
269271
pub fn as_host(&self) -> &ByteBuffer {
270272
self.as_host_opt().vortex_expect("expected host buffer")
271273
}

‎vortex-array/src/builders/varbinview.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ impl ArrayBuilder for VarBinViewBuilder {
367367
}
368368

369369
impl VarBinViewBuilder {
370+
#[inline]
370371
fn push_view(
371372
&mut self,
372373
view: BinaryView,
@@ -758,6 +759,7 @@ enum PrecomputedViewAdjustment {
758759
}
759760

760761
impl PrecomputedViewAdjustment {
762+
#[inline]
761763
fn adjust_view(&self, view: &BinaryView) -> BinaryView {
762764
if view.is_inlined() {
763765
return *view;
@@ -815,6 +817,7 @@ struct RewritingViewAdjustment {
815817
impl RewritingViewAdjustment {
816818
/// Can return None if this view can't be adjusted, because there is no precomputed lookup
817819
/// for the current buffer.
820+
#[inline]
818821
fn adjust_view(&self, view: &BinaryView) -> Option<BinaryView> {
819822
if view.is_inlined() {
820823
return Some(*view);

‎vortex-array/src/canonical.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ pub struct AnyCanonical;
10721072
impl Matcher for AnyCanonical {
10731073
type Match<'a> = CanonicalView<'a>;
10741074

1075+
#[inline]
10751076
fn matches(array: &ArrayRef) -> bool {
10761077
array.is::<Null>()
10771078
|| array.is::<Bool>()
@@ -1085,6 +1086,7 @@ impl Matcher for AnyCanonical {
10851086
|| array.is::<Extension>()
10861087
}
10871088

1089+
#[inline]
10881090
fn try_match(array: &ArrayRef) -> Option<Self::Match<'_>> {
10891091
if let Some(a) = array.as_opt::<Null>() {
10901092
Some(CanonicalView::Null(a))

‎vortex-array/src/matcher.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub trait Matcher {
88
type Match<'a>;
99

1010
/// Check if the given array matches this matcher type
11+
#[inline]
1112
fn matches(array: &ArrayRef) -> bool {
1213
Self::try_match(array).is_some()
1314
}

‎vortex-array/src/search_sorted.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,12 @@ pub trait IndexOrd<V> {
103103
/// For example, if self\[idx\] > elem, return Some(Greater).
104104
fn index_cmp(&self, idx: usize, elem: &V) -> VortexResult<Option<Ordering>>;
105105

106+
#[inline]
106107
fn index_lt(&self, idx: usize, elem: &V) -> VortexResult<bool> {
107108
Ok(matches!(self.index_cmp(idx, elem)?, Some(Less)))
108109
}
109110

111+
#[inline]
110112
fn index_le(&self, idx: usize, elem: &V) -> VortexResult<bool> {
111113
Ok(matches!(self.index_cmp(idx, elem)?, Some(Less | Equal)))
112114
}
@@ -132,6 +134,7 @@ pub trait IndexOrd<V> {
132134
/// |left |array\[i-1\] < value <= array\[i\]|
133135
/// |right|array\[i-1\] <= value < array\[i\]|
134136
pub trait SearchSorted<T> {
137+
#[inline]
135138
fn search_sorted(&self, value: &T, side: SearchSortedSide) -> VortexResult<SearchResult>
136139
where
137140
Self: IndexOrd<T>,
@@ -180,6 +183,7 @@ impl<S, T> SearchSorted<T> for S
180183
where
181184
S: IndexOrd<T> + ?Sized,
182185
{
186+
#[inline]
183187
fn search_sorted_by<
184188
F: FnMut(usize) -> VortexResult<Ordering>,
185189
N: FnMut(usize) -> VortexResult<Ordering>,
@@ -210,6 +214,7 @@ where
210214
}
211215

212216
// Code adapted from Rust standard library slice::binary_search_by
217+
#[inline]
213218
fn search_sorted_side_idx<F: FnMut(usize) -> VortexResult<Ordering>>(
214219
mut find: F,
215220
from: usize,
@@ -276,11 +281,13 @@ impl IndexOrd<Scalar> for ArrayRef {
276281
}
277282

278283
impl<T: PartialOrd> IndexOrd<T> for [T] {
284+
#[inline]
279285
fn index_cmp(&self, idx: usize, elem: &T) -> VortexResult<Option<Ordering>> {
280286
// SAFETY: Used in search_sorted_by same as the standard library. The search_sorted ensures idx is in bounds
281287
Ok(unsafe { self.get_unchecked(idx) }.partial_cmp(elem))
282288
}
283289

290+
#[inline]
284291
fn index_len(&self) -> usize {
285292
self.len()
286293
}

‎vortex-buffer/src/bit/buf_mut.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ impl From<Vec<bool>> for BitBufferMut {
581581
}
582582

583583
impl FromIterator<bool> for BitBufferMut {
584+
#[inline]
584585
fn from_iter<T: IntoIterator<Item = bool>>(iter: T) -> Self {
585586
let mut iter = iter.into_iter();
586587

0 commit comments

Comments
 (0)