Skip to content

Commit

Permalink
Change EntityPathHash to be 64 bit (#1723)
Browse files Browse the repository at this point in the history
* Change EntityPathHash to be 64 bit

* use write! macro instead of f.write_str

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
  • Loading branch information
Wumpf and emilk committed Mar 29, 2023
1 parent d3b459f commit 1f1791a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 2 additions & 0 deletions crates/re_log_types/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use std::hash::BuildHasher;
pub struct Hash64(u64);

impl Hash64 {
pub const ZERO: Hash64 = Hash64(0);

pub fn hash(value: impl std::hash::Hash + Copy) -> Self {
Self(hash(value))
}
Expand Down
18 changes: 7 additions & 11 deletions crates/re_log_types/src/path/entity_path.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::sync::Arc;

use crate::{
hash::Hash128, parse_entity_path, path::entity_path_impl::EntityPathImpl, EntityPathPart,
hash::Hash64, parse_entity_path, path::entity_path_impl::EntityPathImpl, EntityPathPart,
};

// ----------------------------------------------------------------------------

/// A 128 bit hash of [`EntityPath`] with negligible risk of collision.
/// A 64 bit hash of [`EntityPath`] with very small risk of collision.
#[derive(Copy, Clone, Eq)]
pub struct EntityPathHash(Hash128);
pub struct EntityPathHash(Hash64);

impl EntityPathHash {
/// Sometimes used as the hash of `None`.
pub const NONE: EntityPathHash = EntityPathHash(Hash128::ZERO);
pub const NONE: EntityPathHash = EntityPathHash(Hash64::ZERO);

#[inline]
pub fn hash64(&self) -> u64 {
Expand All @@ -33,7 +33,7 @@ impl EntityPathHash {
impl std::hash::Hash for EntityPathHash {
#[inline]
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
state.write_u64(self.0.hash64());
self.0.hash(state);
}
}

Expand All @@ -48,11 +48,7 @@ impl nohash_hasher::IsEnabled for EntityPathHash {}

impl std::fmt::Debug for EntityPathHash {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&format!(
"EntityPathHash({:016X}{:016X})",
self.0.first64(),
self.0.second64()
))
write!(f, "EntityPathHash({:016X})", self.hash64())
}
}

Expand Down Expand Up @@ -164,7 +160,7 @@ impl From<EntityPathImpl> for EntityPath {
#[inline]
fn from(path: EntityPathImpl) -> Self {
Self {
hash: EntityPathHash(Hash128::hash(&path)),
hash: EntityPathHash(Hash64::hash(&path)),
path: Arc::new(path),
}
}
Expand Down

1 comment on commit 1f1791a

@github-actions
Copy link

Choose a reason for hiding this comment

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

Rust Benchmark

Benchmark suite Current: 1f1791a Previous: d3b459f Ratio
datastore/insert/batch/rects/insert 604916 ns/iter (± 1704) 613360 ns/iter (± 2450) 0.99
datastore/latest_at/batch/rects/query 1871 ns/iter (± 2) 1854 ns/iter (± 12) 1.01
datastore/latest_at/missing_components/primary 283 ns/iter (± 1) 285 ns/iter (± 1) 0.99
datastore/latest_at/missing_components/secondaries 434 ns/iter (± 0) 437 ns/iter (± 3) 0.99
datastore/range/batch/rects/query 153548 ns/iter (± 388) 153084 ns/iter (± 1736) 1.00
mono_points_arrow/generate_message_bundles 44548872 ns/iter (± 764710) 45095447 ns/iter (± 815265) 0.99
mono_points_arrow/generate_messages 181860171 ns/iter (± 1302133) 183869457 ns/iter (± 1497684) 0.99
mono_points_arrow/encode_log_msg 222431426 ns/iter (± 1062884) 222487012 ns/iter (± 1418038) 1.00
mono_points_arrow/encode_total 447867584 ns/iter (± 1669452) 449525904 ns/iter (± 2751440) 1.00
mono_points_arrow/decode_log_msg 266281764 ns/iter (± 1017764) 265744193 ns/iter (± 1871293) 1.00
mono_points_arrow/decode_message_bundles 95347641 ns/iter (± 1029190) 99878259 ns/iter (± 874456) 0.95
mono_points_arrow/decode_total 362483952 ns/iter (± 1618307) 364404996 ns/iter (± 2309100) 0.99
mono_points_arrow_batched/generate_message_bundles 34624454 ns/iter (± 2336250) 35268140 ns/iter (± 2123546) 0.98
mono_points_arrow_batched/generate_messages 9713815 ns/iter (± 851019) 9356328 ns/iter (± 812413) 1.04
mono_points_arrow_batched/encode_log_msg 1769737 ns/iter (± 16169) 1808729 ns/iter (± 8582) 0.98
mono_points_arrow_batched/encode_total 47728270 ns/iter (± 2667756) 49341341 ns/iter (± 1943977) 0.97
mono_points_arrow_batched/decode_log_msg 971167 ns/iter (± 4061) 991089 ns/iter (± 4752) 0.98
mono_points_arrow_batched/decode_message_bundles 17318155 ns/iter (± 1991361) 17540706 ns/iter (± 1258358) 0.99
mono_points_arrow_batched/decode_total 19165108 ns/iter (± 1065307) 20186464 ns/iter (± 1180501) 0.95
batch_points_arrow/generate_message_bundles 286779 ns/iter (± 534) 279031 ns/iter (± 2259) 1.03
batch_points_arrow/generate_messages 7956 ns/iter (± 19) 7659 ns/iter (± 96) 1.04
batch_points_arrow/encode_log_msg 385614 ns/iter (± 1220) 391445 ns/iter (± 2031) 0.99
batch_points_arrow/encode_total 693373 ns/iter (± 1835) 697272 ns/iter (± 5100) 0.99
batch_points_arrow/decode_log_msg 338533 ns/iter (± 704) 323104 ns/iter (± 1240) 1.05
batch_points_arrow/decode_message_bundles 2905 ns/iter (± 15) 2859 ns/iter (± 27) 1.02
batch_points_arrow/decode_total 347684 ns/iter (± 6006) 332868 ns/iter (± 2468) 1.04
arrow_mono_points/insert 6845684190 ns/iter (± 18410707) 6918828701 ns/iter (± 18334367) 0.99
arrow_mono_points/query 1777679 ns/iter (± 12548) 1799250 ns/iter (± 16872) 0.99
arrow_batch_points/insert 2994167 ns/iter (± 8352) 3065257 ns/iter (± 19725) 0.98
arrow_batch_points/query 17183 ns/iter (± 36) 16274 ns/iter (± 34) 1.06
arrow_batch_vecs/insert 43095 ns/iter (± 190) 44550 ns/iter (± 633) 0.97
arrow_batch_vecs/query 506123 ns/iter (± 722) 531374 ns/iter (± 5794) 0.95
tuid/Tuid::random 34 ns/iter (± 0) 34 ns/iter (± 0) 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.