Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add metering for deserialization #524

Merged
merged 33 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ab91b4c
add metering for deserialization
chenyan-dfinity Feb 15, 2024
d81d25c
count type table cost
chenyan-dfinity Feb 16, 2024
1e2cef8
increase limit
chenyan-dfinity Feb 16, 2024
dc9a196
make this opt-in
chenyan-dfinity Feb 16, 2024
e15f53f
fix
chenyan-dfinity Feb 16, 2024
fc5ead5
fix
chenyan-dfinity Feb 16, 2024
2b719d3
make skipping twice expensive
chenyan-dfinity Feb 17, 2024
9bf1902
use canbench
chenyan-dfinity Feb 18, 2024
910f2b8
ci
chenyan-dfinity Feb 19, 2024
89f2507
fix
chenyan-dfinity Feb 19, 2024
1519363
fix
chenyan-dfinity Feb 19, 2024
10d4a9f
fix
chenyan-dfinity Feb 19, 2024
bbf58fa
fix
chenyan-dfinity Feb 20, 2024
d47397b
fix
chenyan-dfinity Feb 20, 2024
0570152
Merge remote-tracking branch 'origin/bench' into cost-metering
chenyan-dfinity Feb 20, 2024
99695d1
make skipping 50x expensive
chenyan-dfinity Feb 20, 2024
05d4863
Merge remote-tracking branch 'origin/master' into cost-metering
chenyan-dfinity Feb 20, 2024
1431e97
add diff
chenyan-dfinity Feb 21, 2024
c1d9bd5
fix
chenyan-dfinity Feb 21, 2024
9d8d1be
fix
chenyan-dfinity Feb 21, 2024
de4cb9e
fix
chenyan-dfinity Feb 21, 2024
963c136
fix
chenyan-dfinity Feb 21, 2024
3279530
Merge remote-tracking branch 'origin/master' into cost-metering
chenyan-dfinity Feb 21, 2024
6146965
add skipping limit
chenyan-dfinity Feb 22, 2024
1fe4a3e
fix cycle detection
chenyan-dfinity Feb 22, 2024
719fe86
fix
chenyan-dfinity Feb 22, 2024
0acf42c
spec
chenyan-dfinity Feb 23, 2024
7e6afa7
test
chenyan-dfinity Feb 23, 2024
1a71d0a
docs
chenyan-dfinity Feb 24, 2024
5edef7b
fix
chenyan-dfinity Feb 24, 2024
42c26d7
fix
chenyan-dfinity Feb 24, 2024
7ddd69a
refine cost description
chenyan-dfinity Feb 27, 2024
2bc6db1
test description
chenyan-dfinity Feb 27, 2024
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
24 changes: 13 additions & 11 deletions rust/candid/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use candid::{CandidType, Decode, Deserialize, Encode, Int, Nat, Principal};
use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
use std::collections::BTreeMap;

const COST: usize = 20_000_000;

fn bench_blob(c: &mut Criterion) {
use serde_bytes::{ByteBuf, Bytes};
let vec: Vec<u8> = vec![0x61; 524288];
Expand All @@ -11,7 +13,7 @@ fn bench_blob(c: &mut Criterion) {
|| vec.clone(),
|vec| {
let bytes = Encode!(&ByteBuf::from(vec)).unwrap();
Decode!(&bytes, ByteBuf).unwrap();
Decode!([COST]; &bytes, ByteBuf).unwrap();
},
BatchSize::SmallInput,
)
Expand All @@ -21,7 +23,7 @@ fn bench_blob(c: &mut Criterion) {
|| vec.clone(),
|vec| {
let bytes = Encode!(&Bytes::new(vec)).unwrap();
Decode!(&bytes, &Bytes).unwrap();
Decode!([COST]; &bytes, &Bytes).unwrap();
},
BatchSize::SmallInput,
)
Expand All @@ -32,7 +34,7 @@ fn bench_blob(c: &mut Criterion) {
|| text.clone(),
|text| {
let bytes = Encode!(&text).unwrap();
Decode!(&bytes, String).unwrap();
Decode!([COST]; &bytes, String).unwrap();
},
BatchSize::SmallInput,
)
Expand All @@ -42,7 +44,7 @@ fn bench_blob(c: &mut Criterion) {
|| text.clone(),
|text| {
let bytes = Encode!(text).unwrap();
Decode!(&bytes, &str).unwrap();
Decode!([COST]; &bytes, &str).unwrap();
},
BatchSize::SmallInput,
)
Expand All @@ -59,7 +61,7 @@ fn bench_collections(c: &mut Criterion) {
|| vec8.clone(),
|vec| {
let bytes = Encode!(&vec).unwrap();
Decode!(&bytes, Vec<u8>).unwrap();
Decode!([COST]; &bytes, Vec<u8>).unwrap();
},
BatchSize::SmallInput,
)
Expand All @@ -72,7 +74,7 @@ fn bench_collections(c: &mut Criterion) {
|| vec64.clone(),
|vec| {
let bytes = Encode!(&vec).unwrap();
Decode!(&bytes, Vec<i64>).unwrap();
Decode!([COST]; &bytes, Vec<i64>).unwrap();
},
BatchSize::SmallInput,
)
Expand All @@ -85,7 +87,7 @@ fn bench_collections(c: &mut Criterion) {
|| vec.clone(),
|vec| {
let bytes = Encode!(&vec).unwrap();
Decode!(&bytes, Vec<candid::Int>).unwrap();
Decode!([COST]; &bytes, Vec<candid::Int>).unwrap();
},
BatchSize::SmallInput,
)
Expand All @@ -100,7 +102,7 @@ fn bench_collections(c: &mut Criterion) {
|| map.clone(),
|map| {
let bytes = Encode!(&map).unwrap();
Decode!(&bytes, BTreeMap<String, Nat>).unwrap();
Decode!([COST]; &bytes, BTreeMap<String, Nat>).unwrap();
},
BatchSize::SmallInput,
)
Expand Down Expand Up @@ -130,7 +132,7 @@ fn bench_recursion(c: &mut Criterion) {
c.bench_with_input(BenchmarkId::new("option list", n), &list, |b, list| {
b.iter(|| {
let bytes = Encode!(list).unwrap();
Decode!(&bytes, Option<Box<List>>).unwrap()
Decode!([COST]; &bytes, Option<Box<List>>).unwrap()
})
});
}
Expand All @@ -141,7 +143,7 @@ fn bench_recursion(c: &mut Criterion) {
c.bench_with_input(BenchmarkId::new("variant list", n), &list, |b, list| {
b.iter(|| {
let bytes = Encode!(list).unwrap();
Decode!(&bytes, VariantList).unwrap()
Decode!([COST]; &bytes, VariantList).unwrap()
})
});
}
Expand Down Expand Up @@ -177,7 +179,7 @@ fn bench_profile(c: &mut Criterion) {
|b, vec| {
b.iter(|| {
let bytes = Encode!(vec).unwrap();
Decode!(&bytes, Vec<Profile>).unwrap()
Decode!([COST]; &bytes, Vec<Profile>).unwrap()
})
},
);
Expand Down
Loading
Loading