Skip to content

Commit

Permalink
Try to use dashmap
Browse files Browse the repository at this point in the history
This fixes the performance regression for me, but we need to think whether that's worth the dependency tradeoff.
  • Loading branch information
strohel committed Aug 7, 2024
1 parent f057ce1 commit 3befcec
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ keywords = ["actor", "threads"]
flume = { version = "0.10", default-features = false, features = ["select"] }
log = "0.4"
parking_lot = "0.12"
dashmap = "6"

[dev-dependencies]
anyhow = "1"
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ struct EventSubscribers {
events: HashMap<TypeId, Vec<EventCallback>>,
/// We cache the last published value of each event type.
/// Subscribers can request to receive it upon subscription.
last_value_cache: HashMap<TypeId, Box<dyn std::any::Any + Send + Sync>>,
last_value_cache: dashmap::DashMap<TypeId, Box<dyn std::any::Any + Send + Sync>>,
}

/// Contains the "metadata" of the system, including information about the registry
Expand Down Expand Up @@ -778,7 +778,7 @@ impl SystemHandle {
/// When sending to some subscriber fails, others are still tried and vec of errors is returned.
/// For direct, non-[`Clone`] or high-throughput messages please use [`Addr`] or [`Recipient`].
pub fn publish<E: Event>(&self, event: E) -> Result<(), PublishError> {
let mut event_subscribers = self.event_subscribers.write();
let event_subscribers = self.event_subscribers.read();
let type_id = TypeId::of::<E>();

event_subscribers.last_value_cache.insert(type_id, Box::new(event.clone()));
Expand Down

0 comments on commit 3befcec

Please sign in to comment.