Skip to content

Commit

Permalink
Merge pull request #1292 from TTWNO/no-clone-sig-body
Browse files Browse the repository at this point in the history
⚡️zb: don't clone signature when creating body
  • Loading branch information
zeenix authored Mar 9, 2025
2 parents 76ae834 + 80ff227 commit de84e0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
5 changes: 5 additions & 0 deletions zbus/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ fn msg_de(c: &mut Criterion) {
b.iter(|| {
let header = msg.header();
black_box(header);
let body = msg.body();
let signature = body.signature();
black_box(signature);
})
});

Expand All @@ -43,6 +46,8 @@ fn msg_de(c: &mut Criterion) {
g.bench_function("body", |b| {
b.iter(|| {
let body = msg.body();
let signature = body.signature();
black_box(signature);
let body: BigBoy<'_> = body.deserialize().unwrap();
black_box(body);
})
Expand Down
14 changes: 3 additions & 11 deletions zbus/src/message/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,19 @@ use crate::{Error, Message, Result};
pub struct Body {
data: Data<'static, 'static>,
msg: Message,
signature: Signature,
}

impl Body {
pub(super) fn new(data: Data<'static, 'static>, msg: Message) -> Self {
let body_sig = msg.header().signature().clone();

Self {
data,
msg,
signature: body_sig,
}
Self { data, msg }
}

/// Deserialize the body using the contained signature.
pub fn deserialize<'s, B>(&'s self) -> Result<B>
where
B: zvariant::DynamicDeserialize<'s>,
{
let header = self.msg.header();
let body_sig = header.signature();
let body_sig = self.signature();

self.data
.deserialize_for_dynamic_signature(body_sig)
Expand All @@ -50,7 +42,7 @@ impl Body {

/// The signature of the body.
pub fn signature(&self) -> &Signature {
&self.signature
self.msg.quick_fields().signature()
}

/// The length of the body in bytes.
Expand Down

1 comment on commit de84e0a

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: de84e0a Previous: 76ae834 Ratio
dbus/fixed_size_array_ser 597702 ns/iter (± 735) 167226 ns/iter (± 285) 3.57

This comment was automatically generated by workflow using github-action-benchmark.

CC: @zeenix

Please sign in to comment.