Skip to content

Commit

Permalink
benchmark: Provide some data to the store so the search and disambigu…
Browse files Browse the repository at this point in the history
…ation happen
  • Loading branch information
jmartinesp committed Mar 8, 2024
1 parent 31c0166 commit b985fce
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions benchmarks/benches/room_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use matrix_sdk_test::EventBuilder;
use ruma::{
api::client::membership::get_member_events,
device_id,
events::room::member::{RoomMemberEvent, RoomMemberEventContent},
events::{
room::member::{RoomMemberEvent, RoomMemberEventContent, SyncRoomMemberEvent},
AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent,
},
owned_room_id,
serde::Raw,
user_id, OwnedUserId,
Expand All @@ -18,30 +21,8 @@ use tokio::runtime::Builder;

pub fn receive_all_members_benchmark(c: &mut Criterion) {
let runtime = Builder::new_multi_thread().build().expect("Can't create runtime");

// Create a fake list of changes, and a session to recover from.
let mut changes = StateChanges::default();

let room_id = owned_room_id!("!room:example.com");
changes.add_room(RoomInfo::new(&room_id, RoomState::Joined));

// Sqlite
let sqlite_dir = tempfile::tempdir().unwrap();
let sqlite_store = runtime.block_on(SqliteStateStore::open(sqlite_dir.path(), None)).unwrap();
runtime
.block_on(sqlite_store.save_changes(&changes))
.expect("initial filling of sqlite failed");

let base_client = BaseClient::with_store_config(StoreConfig::new().state_store(sqlite_store));
runtime
.block_on(base_client.set_session_meta(SessionMeta {
user_id: user_id!("@somebody:example.com").to_owned(),
device_id: device_id!("DEVICE_ID").to_owned(),
}))
.expect("Could not set session meta");
base_client.get_or_create_room(&room_id, RoomState::Joined);

let members_in_room = 100000;
let room_id = owned_room_id!("!room:example.com");

let ev_builder = EventBuilder::new();
let mut member_events: Vec<Raw<RoomMemberEvent>> = Vec::with_capacity(members_in_room as usize);
Expand All @@ -55,7 +36,7 @@ pub fn receive_all_members_benchmark(c: &mut Criterion) {
member_content_json.into_raw_state_event_content().cast();
for i in 0..members_in_room {
let user_id = OwnedUserId::try_from(format!("@user_{}:matrix.org", i)).unwrap();
let state_key = format!("ev_{i}");
let state_key = user_id.to_string();
let event: Raw<RoomMemberEvent> = ev_builder
.make_state_event(
&user_id,
Expand All @@ -68,13 +49,38 @@ pub fn receive_all_members_benchmark(c: &mut Criterion) {
member_events.push(event);
}

// Create a fake list of changes, and a session to recover from.
let mut changes = StateChanges::default();
changes.add_room(RoomInfo::new(&room_id, RoomState::Joined));
for member_event in member_events.iter() {
let event = member_event.clone().cast();
changes.add_state_event(&room_id, event.deserialize().unwrap(), event);
}

// Sqlite
let sqlite_dir = tempfile::tempdir().unwrap();
let sqlite_store = runtime.block_on(SqliteStateStore::open(sqlite_dir.path(), None)).unwrap();
runtime
.block_on(sqlite_store.save_changes(&changes))
.expect("initial filling of sqlite failed");

let base_client = BaseClient::with_store_config(StoreConfig::new().state_store(sqlite_store));
runtime
.block_on(base_client.set_session_meta(SessionMeta {
user_id: user_id!("@somebody:example.com").to_owned(),
device_id: device_id!("DEVICE_ID").to_owned(),
}))
.expect("Could not set session meta");
base_client.get_or_create_room(&room_id, RoomState::Joined);

let request = get_member_events::v3::Request::new(room_id.clone());
let response = get_member_events::v3::Response::new(member_events);

let count = members_in_room;
let name = format!("{count} members");
let mut group = c.benchmark_group("Test");
group.throughput(Throughput::Elements(count));
group.sample_size(50);

group.bench_function(BenchmarkId::new("receive_members", name), |b| {
b.to_async(&runtime).iter(|| async {
Expand Down

0 comments on commit b985fce

Please sign in to comment.