Skip to content

Commit dca736e

Browse files
committed
perf: Arc::ptr_eq short-circuit for List and FixedSizeList DType equality
Extend the Arc::ptr_eq fast-path from #7398 to cover the remaining Arc-containing DType variants. List and FixedSizeList hold a bare Arc<DType> in the enum variant, so the shortcut is applied in DType's manual PartialEq impl. StructFields already handles its own Arc::ptr_eq internally. The mismatch arms enumerate every variant in the first position so that adding a new DType variant produces a non-exhaustive match compile error. DuckDB StatPopGen full-suite apmc measurement for vortex, averaged over two runs: - Cycles: -5.4% (5,973M → 5,651M) - Instructions: -15.3% (15,491M → 13,121M) - L1D_CACHE_MISS_LD: -0.8% (56.2M → 55.7M) - MAP_STALL: -0.2% (1,347M → 1,344M) Signed-off-by: Alexander Droste <alexander.droste@protonmail.com>
1 parent d4e7dca commit dca736e

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

vortex-array/public-api.lock

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9166,7 +9166,7 @@ impl core::cmp::Eq for vortex_array::dtype::DType
91669166

91679167
impl core::cmp::PartialEq for vortex_array::dtype::DType
91689168

9169-
pub fn vortex_array::dtype::DType::eq(&self, other: &vortex_array::dtype::DType) -> bool
9169+
pub fn vortex_array::dtype::DType::eq(&self, other: &Self) -> bool
91709170

91719171
impl core::convert::From<vortex_array::dtype::DType> for vortex_array::dtype::FieldDType
91729172

@@ -9216,8 +9216,6 @@ impl core::hash::Hash for vortex_array::dtype::DType
92169216

92179217
pub fn vortex_array::dtype::DType::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
92189218

9219-
impl core::marker::StructuralPartialEq for vortex_array::dtype::DType
9220-
92219219
impl vortex_array::dtype::arrow::FromArrowType<&arrow_schema::field::Field> for vortex_array::dtype::DType
92229220

92239221
pub fn vortex_array::dtype::DType::from_arrow(field: &arrow_schema::field::Field) -> Self

vortex-array/src/dtype/mod.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ use std::sync::Arc;
5050
///
5151
/// [`I32`]: PType::I32
5252
/// [`NonNullable`]: Nullability::NonNullable
53-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
53+
#[derive(Debug, Clone, Eq, Hash)]
54+
#[allow(clippy::derived_hash_with_manual_eq)] // manual PartialEq adds Arc::ptr_eq fast path only
5455
pub enum DType {
5556
/// A logical null type.
5657
///
@@ -106,6 +107,42 @@ pub enum DType {
106107
Variant(Nullability),
107108
}
108109

110+
impl PartialEq for DType {
111+
fn eq(&self, other: &Self) -> bool {
112+
match (self, other) {
113+
(Self::Null, Self::Null) => true,
114+
(Self::Bool(a), Self::Bool(b)) => a == b,
115+
(Self::Primitive(pa, na), Self::Primitive(pb, nb)) => pa == pb && na == nb,
116+
(Self::Decimal(da, na), Self::Decimal(db, nb)) => da == db && na == nb,
117+
(Self::Utf8(a), Self::Utf8(b)) => a == b,
118+
(Self::Binary(a), Self::Binary(b)) => a == b,
119+
(Self::List(da, na), Self::List(db, nb)) => {
120+
na == nb && (Arc::ptr_eq(da, db) || da == db)
121+
}
122+
(Self::FixedSizeList(da, sa, na), Self::FixedSizeList(db, sb, nb)) => {
123+
sa == sb && na == nb && (Arc::ptr_eq(da, db) || da == db)
124+
}
125+
// StructFields handles its own Arc::ptr_eq in its PartialEq impl.
126+
(Self::Struct(a, na), Self::Struct(b, nb)) => na == nb && a == b,
127+
(Self::Extension(a), Self::Extension(b)) => a == b,
128+
(Self::Variant(a), Self::Variant(b)) => a == b,
129+
// Every variant is listed in the first position so that adding a new
130+
// variant produces a non-exhaustive match compile error.
131+
(Self::Null, _)
132+
| (Self::Bool(_), _)
133+
| (Self::Primitive(..), _)
134+
| (Self::Decimal(..), _)
135+
| (Self::Utf8(_), _)
136+
| (Self::Binary(_), _)
137+
| (Self::List(..), _)
138+
| (Self::FixedSizeList(..), _)
139+
| (Self::Struct(..), _)
140+
| (Self::Extension(_), _)
141+
| (Self::Variant(_), _) => false,
142+
}
143+
}
144+
}
145+
109146
pub use bigint::*;
110147
pub use decimal::*;
111148
pub use dtype_impl::NativeDType;

0 commit comments

Comments
 (0)