From b985fced483ec6d55fe79e1d2d17e160f5ca8153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Fri, 8 Mar 2024 20:07:34 +0100 Subject: [PATCH] benchmark: Provide some data to the store so the search and disambiguation happen --- benchmarks/benches/room_bench.rs | 56 ++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/benchmarks/benches/room_bench.rs b/benchmarks/benches/room_bench.rs index 4999713271c..6a84597da06 100644 --- a/benchmarks/benches/room_bench.rs +++ b/benchmarks/benches/room_bench.rs @@ -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, @@ -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> = Vec::with_capacity(members_in_room as usize); @@ -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 = ev_builder .make_state_event( &user_id, @@ -68,6 +49,30 @@ 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); @@ -75,6 +80,7 @@ pub fn receive_all_members_benchmark(c: &mut Criterion) { 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 {