Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions wacore/binary/benches/binary_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,44 @@ fn create_small_node() -> Node {
.build()
}

/// The shape the wire is mostly made of: a short ack whose `to` is a JID and
/// whose `id` is hex, so decoding it goes through `read_jid_pair` and
/// `read_packed`. `create_small_node` has neither, which left the two paths
/// that dominate a small-stanza profile uncovered.
Comment thread
jlucaso1 marked this conversation as resolved.
Outdated
Comment thread
jlucaso1 marked this conversation as resolved.
Outdated
fn create_ack_node() -> Node {
NodeBuilder::new("ack")
.attr("to", "5511999990000@s.whatsapp.net")
.attr("id", "3EB0A1B2C3D4E5F60718")
.attr("class", "message")
.build()
}

/// A device fanout, where the same two paths repeat per child.
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated
Comment thread
jlucaso1 marked this conversation as resolved.
Outdated
fn create_fanout_node() -> Node {
let devices: Vec<Node> = (0..8)
.map(|i| {
NodeBuilder::new("to")
.attr("jid", format!("5511999990000:{i}@s.whatsapp.net"))
.children(vec![
NodeBuilder::new("enc")
.attr("v", "2")
.attr("type", "msg")
.bytes(vec![0xAB; 128])
.build(),
])
.build()
})
.collect();
NodeBuilder::new("message")
.attr("to", "5511999990000@g.us")
.attr("id", "3EB0A1B2C3D4E5F60718")
.attr("type", "text")
.children(vec![
NodeBuilder::new("participants").children(devices).build(),
])
.build()
}

fn create_large_node() -> Node {
NodeBuilder::new("iq")
.attr("to", "server@s.whatsapp.net")
Expand Down Expand Up @@ -243,6 +281,32 @@ fn bench_unmarshal_small(bencher: divan::Bencher) {
});
}

fn setup_ack_marshaled() -> Vec<u8> {
marshal(&create_ack_node()).unwrap()
Comment thread
jlucaso1 marked this conversation as resolved.
}

fn setup_fanout_marshaled() -> Vec<u8> {
marshal(&create_fanout_node()).unwrap()
}

#[divan::bench]
fn bench_unmarshal_ack(bencher: divan::Bencher) {
bencher
.with_inputs(setup_ack_marshaled)
.bench_refs(|marshaled| {
black_box(unmarshal_ref(black_box(&marshaled[1..])).unwrap());
});
}

#[divan::bench]
fn bench_unmarshal_fanout(bencher: divan::Bencher) {
bencher
.with_inputs(setup_fanout_marshaled)
.bench_refs(|marshaled| {
black_box(unmarshal_ref(black_box(&marshaled[1..])).unwrap());
});
}

#[divan::bench]
fn bench_unmarshal_large(bencher: divan::Bencher) {
bencher
Expand Down
Loading