Skip to content

Commit

Permalink
Merge pull request #1090 from zeenix/port-to-winnow
Browse files Browse the repository at this point in the history
zu: Switch from `nom` to `winnow` for signature parsing
  • Loading branch information
zeenix authored Oct 20, 2024
2 parents 89cb6fc + df6b4e1 commit c36d30f
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 155 deletions.
72 changes: 18 additions & 54 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion zbus_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ proc-macro = true
proc-macro2 = "1.0.81"
syn = { version = "2.0.64", features = ["extra-traits", "fold", "full"] }
quote = "1.0.36"
proc-macro-crate = "3.1.0"
proc-macro-crate = "3.2.0"
zvariant_utils = { path = "../zvariant_utils", version = "=3.0.0" }

[dev-dependencies]
Expand Down
96 changes: 66 additions & 30 deletions zvariant/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,6 @@ fn fixed_size_array(c: &mut Criterion) {
}

fn big_array(c: &mut Criterion) {
#[derive(Deserialize, Serialize, Type, PartialEq, Debug, Clone)]
struct BigArrayField<'f> {
int2: u64,
string2: &'f str,
}

#[derive(Deserialize, Serialize, Type, PartialEq, Debug, Clone)]
struct BigArrayStruct<'s> {
string1: &'s str,
int1: u64,
field: BigArrayField<'s>,
int_array: Vec<u64>,
string_array: Vec<&'s str>,
}

let mut asv_dict = HashMap::new();
let mut ass_dict = HashMap::new();
let int_array = vec![0u64; 1024 * 10];
Expand Down Expand Up @@ -116,25 +101,12 @@ fn big_array(c: &mut Criterion) {

benchmark!(c, structure, BigArrayStruct<'_>, "big_array");

#[derive(Deserialize, Serialize, Type, PartialEq, Debug)]
struct BigArrayDictStruct<'s> {
#[serde(borrow)]
array_struct: BigArrayStruct<'s>,
dict: HashMap<&'s str, &'s str>,
}
let data = BigArrayDictStruct {
array_struct: structure.clone(),
dict: ass_dict,
};
benchmark!(c, data, BigArrayDictStruct<'_>, "big_array_and_ass_dict");

#[derive(Deserialize, Serialize, Type, PartialEq, Debug)]
struct BigArrayDictVariantStruct<'s> {
#[serde(borrow)]
array_struct: BigArrayStruct<'s>,
dict: HashMap<&'s str, Value<'s>>,
}

let data = BigArrayDictVariantStruct {
array_struct: structure,
dict: asv_dict,
Expand All @@ -147,8 +119,72 @@ fn big_array(c: &mut Criterion) {
);
}

fn signature_parse(c: &mut Criterion) {
#[derive(Type, PartialEq, Debug)]
struct LongSignatureStruct {
f1: BigArrayDictVariantStruct<'static>,
f2: BigArrayDictVariantStruct<'static>,
f3: BigArrayDictVariantStruct<'static>,
f4: BigArrayDictVariantStruct<'static>,
f5: BigArrayDictVariantStruct<'static>,
f6: BigArrayDictVariantStruct<'static>,
f7: BigArrayDictVariantStruct<'static>,
f8: BigArrayDictVariantStruct<'static>,
f9: BigArrayDictVariantStruct<'static>,
f10: BigArrayDictVariantStruct<'static>,
f11: BigArrayDictVariantStruct<'static>,
f12: BigArrayDictVariantStruct<'static>,
f13: BigArrayDictVariantStruct<'static>,
f14: (u32, String, u64, i32),
}
let signature_str = LongSignatureStruct::SIGNATURE.to_string();
// Ensure we have the maximum signature length allowed by the spec.
assert_eq!(signature_str.len(), 255);

c.bench_function("signature_parse", |b| {
b.iter(|| {
zvariant::Signature::try_from(black_box(signature_str.as_str())).unwrap();
})
});
}

#[derive(Deserialize, Serialize, Type, PartialEq, Debug, Clone)]
struct BigArrayField<'f> {
int2: u64,
string2: &'f str,
}

#[derive(Deserialize, Serialize, Type, PartialEq, Debug, Clone)]
struct BigArrayStruct<'s> {
string1: &'s str,
int1: u64,
field: BigArrayField<'s>,
int_array: Vec<u64>,
string_array: Vec<&'s str>,
}

#[derive(Deserialize, Serialize, Type, PartialEq, Debug)]
struct BigArrayDictStruct<'s> {
#[serde(borrow)]
array_struct: BigArrayStruct<'s>,
dict: HashMap<&'s str, &'s str>,
}

#[derive(Deserialize, Serialize, Type, PartialEq, Debug)]
struct BigArrayDictVariantStruct<'s> {
#[serde(borrow)]
array_struct: BigArrayStruct<'s>,
dict: HashMap<&'s str, Value<'s>>,
}

#[cfg(feature = "serde_bytes")]
criterion_group!(benches, big_array, byte_array, fixed_size_array);
criterion_group!(
benches,
big_array,
byte_array,
fixed_size_array,
signature_parse
);
#[cfg(not(feature = "serde_bytes"))]
criterion_group!(benches, big_array, fixed_size_array);
criterion_group!(benches, big_array, fixed_size_array, signature_parse);
criterion_main!(benches);
2 changes: 1 addition & 1 deletion zvariant/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ mod tests {
let gv_ser_value_encoded =
zvariant::to_bytes(ctxt, &zvariant::SerializeValue(&map)).unwrap();
let gv_value_encoded = to_bytes(ctxt, &zvariant::Value::new(map)).unwrap();
assert_eq!(gv_value_encoded.as_ref(), gv_ser_value_encoded.as_ref());
assert_eq!(*gv_value_encoded, *gv_ser_value_encoded);

// Check encoding against GLib
let bytes = Bytes::from_owned(gv_encoded);
Expand Down
2 changes: 1 addition & 1 deletion zvariant_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gvariant = ["zvariant_utils/gvariant", "zvariant/gvariant"]
proc-macro2 = "1.0.81"
syn = { version = "2.0.64", features = ["extra-traits", "full"] }
quote = "1.0.36"
proc-macro-crate = "3.1.0"
proc-macro-crate = "3.2.0"
zvariant_utils = { path = "../zvariant_utils", version = "=3.0.0" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion zvariant_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ syn = { version = "2.0.64", features = ["extra-traits", "full"] }
quote = "1.0.36"
static_assertions = "1.1.0"
serde = "1.0.200"
nom = "7"
winnow = "0.6"

[dev-dependencies]
zvariant = { path = "../zvariant" }
Expand Down
Loading

0 comments on commit c36d30f

Please sign in to comment.