Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSDK-2011 Change CHashMap to DashMap for better performance #31

Merged
merged 2 commits into from
Mar 9, 2023

Conversation

benjirewis
Copy link
Member

@benjirewis benjirewis commented Mar 9, 2023

RSDK-2011

DashMap has an almost identical API to CHashMap but anecdotally has better performance under high workloads (e.g. lots of concurrent writes). Switching to DashMap seems to resolve hangs with async calls from the Python SDK (see RSDK-2011 and RSDK-2070).

Note that users will still run into the issue of stream ID integer overflow in the underlying webrtc-rs crate until we do RSDK-2268.

@benjirewis benjirewis requested a review from stuqdog March 9, 2023 20:01
@benjirewis benjirewis requested a review from a team as a code owner March 9, 2023 20:01
Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

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

lgtm with one small nit :) thanks for digging into this!

Cargo.toml Outdated
@@ -45,6 +44,7 @@ tracing = {version = "0.1.34"}
tracing-subscriber = {version = "0.3.11", features = ["env-filter"]}
webpki-roots = "0.21.1"
webrtc = "0.6.0"
dashmap = "5.4.0"
Copy link
Member

Choose a reason for hiding this comment

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

(nit) would love to keep dependencies alphabetized

Comment on lines +167 to +170
match self.receiver_bodies.remove(&stream_id) {
Some(entry) => Ok(entry.1),
None => Err(anyhow::anyhow!("Tried to receive stream {stream_id} but it didn't exist!")),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

[minor] why can't we (or shouldn't we) keep using the Option#ok_or method with this new data structure?

Copy link
Member

@stuqdog stuqdog Mar 9, 2023

Choose a reason for hiding this comment

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

the remove api is slightly different with DashMap, it doesn't give us exactly what we want (the stored value) but rather a key value tuple. the match is a bit cleaner for indexing into the tuple (note the .1 on line 168).

edit: I guess "cleaner" is just opinion, and we certainly could use the ok_or and add a .1 at the end, but it seems a little ugly personally!

Copy link
Member Author

Choose a reason for hiding this comment

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

CHashMap::remove returned an Option<V> while DashMap::remove returns an Option<(K,V)>. We don't really care about the K (a u64 ID), and only want to return the V (a stream). Extracting the stream requires accessing it from the tuple with .1; I wasn't able to do that with ok_or, but definitely possible I just didn't know how.

@benjirewis benjirewis merged commit 2bb12f6 into viamrobotics:main Mar 9, 2023
@benjirewis benjirewis deleted the RSDK-2011 branch March 9, 2023 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants