|
6 | 6 | use crate::tracing::Instrument;
|
7 | 7 | use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
|
8 | 8 | use tokio::runtime::{Builder, Runtime};
|
9 |
| -use xmtp_common::{bench::BENCH_ROOT_SPAN, tmp_path}; |
| 9 | +use xmtp_common::{ |
| 10 | + bench::{bench_async_setup, BENCH_ROOT_SPAN}, |
| 11 | + tmp_path, |
| 12 | +}; |
10 | 13 | use xmtp_id::InboxOwner;
|
11 | 14 | use xmtp_mls::utils::test::HISTORY_SYNC_URL;
|
12 | 15 | use xmtpv3::generate_inbox_id;
|
@@ -43,30 +46,32 @@ fn create_ffi_client(c: &mut Criterion) {
|
43 | 46 | let mut benchmark_group = c.benchmark_group("create_client");
|
44 | 47 |
|
45 | 48 | // benchmark_group.sample_size(10);
|
46 |
| - benchmark_group.sampling_mode(criterion::SamplingMode::Flat); |
47 | 49 | benchmark_group.bench_function("create_ffi_client", |b| {
|
48 | 50 | let span = trace_span!(BENCH_ROOT_SPAN);
|
49 | 51 | b.to_async(&runtime).iter_batched(
|
50 | 52 | || {
|
51 |
| - let wallet = xmtp_cryptography::utils::generate_local_wallet(); |
52 |
| - let nonce = 1; |
53 |
| - let inbox_id = generate_inbox_id(wallet.get_address(), nonce).unwrap(); |
54 |
| - let path = tmp_path(); |
55 |
| - let (network, is_secure) = network_url(); |
56 |
| - ( |
57 |
| - inbox_id, |
58 |
| - wallet.get_address(), |
59 |
| - nonce, |
60 |
| - path, |
61 |
| - network, |
62 |
| - is_secure, |
63 |
| - span.clone(), |
64 |
| - ) |
| 53 | + bench_async_setup(|| async { |
| 54 | + let wallet = xmtp_cryptography::utils::generate_local_wallet(); |
| 55 | + let nonce = 1; |
| 56 | + let inbox_id = generate_inbox_id(wallet.get_address(), nonce).unwrap(); |
| 57 | + let path = tmp_path(); |
| 58 | + let (url, is_secure) = network_url(); |
| 59 | + let api = xmtpv3::mls::connect_to_backend(url, is_secure) |
| 60 | + .await |
| 61 | + .unwrap(); |
| 62 | + ( |
| 63 | + api, |
| 64 | + inbox_id, |
| 65 | + wallet.get_address(), |
| 66 | + nonce, |
| 67 | + path, |
| 68 | + span.clone(), |
| 69 | + ) |
| 70 | + }) |
65 | 71 | },
|
66 |
| - |(inbox_id, address, nonce, path, network, is_secure, span)| async move { |
| 72 | + |(api, inbox_id, address, nonce, path, span)| async move { |
67 | 73 | xmtpv3::mls::create_client(
|
68 |
| - network, |
69 |
| - is_secure, |
| 74 | + api, |
70 | 75 | Some(path),
|
71 | 76 | Some(vec![0u8; 32]),
|
72 | 77 | &inbox_id,
|
@@ -98,29 +103,44 @@ fn cached_create_ffi_client(c: &mut Criterion) {
|
98 | 103 | let inbox_id = generate_inbox_id(wallet.get_address(), nonce).unwrap();
|
99 | 104 | let address = wallet.get_address();
|
100 | 105 | let path = tmp_path();
|
| 106 | + let (url, is_secure) = network_url(); |
| 107 | + let api = runtime.block_on(async { |
| 108 | + let api = xmtpv3::mls::connect_to_backend(url.clone(), is_secure) |
| 109 | + .await |
| 110 | + .unwrap(); |
| 111 | + xmtpv3::mls::create_client( |
| 112 | + api.clone(), |
| 113 | + Some(path.clone()), |
| 114 | + Some(vec![0u8; 32]), |
| 115 | + &inbox_id.clone(), |
| 116 | + address.clone(), |
| 117 | + nonce, |
| 118 | + None, |
| 119 | + Some(HISTORY_SYNC_URL.to_string()), |
| 120 | + ) |
| 121 | + .await |
| 122 | + .unwrap(); |
| 123 | + api |
| 124 | + }); |
101 | 125 |
|
102 | 126 | // benchmark_group.sample_size(10);
|
103 |
| - benchmark_group.sampling_mode(criterion::SamplingMode::Flat); |
104 | 127 | benchmark_group.bench_function("cached_create_ffi_client", |b| {
|
105 | 128 | let span = trace_span!(BENCH_ROOT_SPAN);
|
106 | 129 | b.to_async(&runtime).iter_batched(
|
107 | 130 | || {
|
108 |
| - let (network, is_secure) = network_url(); |
109 | 131 | (
|
| 132 | + api.clone(), |
110 | 133 | inbox_id.clone(),
|
111 | 134 | address.clone(),
|
112 | 135 | nonce,
|
113 | 136 | path.clone(),
|
114 | 137 | HISTORY_SYNC_URL.to_string(),
|
115 |
| - network, |
116 |
| - is_secure, |
117 | 138 | span.clone(),
|
118 | 139 | )
|
119 | 140 | },
|
120 |
| - |(inbox_id, address, nonce, path, history_sync, network, is_secure, span)| async move { |
| 141 | + |(api, inbox_id, address, nonce, path, history_sync, span)| async move { |
121 | 142 | xmtpv3::mls::create_client(
|
122 |
| - network, |
123 |
| - is_secure, |
| 143 | + api, |
124 | 144 | Some(path),
|
125 | 145 | Some(vec![0u8; 32]),
|
126 | 146 | &inbox_id,
|
|
0 commit comments