diff --git a/Cargo.lock b/Cargo.lock index d8ee7276..f21af487 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -234,7 +234,7 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "candid" -version = "0.10.6" +version = "0.10.7" dependencies = [ "anyhow", "bincode", diff --git a/Changelog.md b/Changelog.md index 72544ca8..e8dcf97c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,15 @@ # Changelog +## 2024-04-11 + +### Candid 0.10.7 -- 0.10.5 + +* Switch `HashMap` to `BTreeMap` in serialization and `T::ty()`. This leads to around 20% perf improvement for serializing complicated types. +* Disable memoization for unrolled types in serialization to save cycle cost. In some cases, type table can get slightly larger, but it's worth the trade off. +* Fix bug in `text_size` +* Fix decoding cost calculation overflow + ## 2024-02-27 ### Candid 0.10.4 diff --git a/rust/candid/Cargo.toml b/rust/candid/Cargo.toml index 733fecbd..93949bae 100644 --- a/rust/candid/Cargo.toml +++ b/rust/candid/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "candid" -version = "0.10.6" +version = "0.10.7" edition = "2021" rust-version.workspace = true authors = ["DFINITY Team"] diff --git a/rust/candid/src/ser.rs b/rust/candid/src/ser.rs index eaaeb1c3..002c6717 100644 --- a/rust/candid/src/ser.rs +++ b/rust/candid/src/ser.rs @@ -262,12 +262,13 @@ impl TypeSerialize { // from the type table. // Someone should implement Pottier's O(nlogn) algorithm // http://gallium.inria.fr/~fpottier/publis/gauthier-fpottier-icfp04.pdf - /*let unrolled = types::internal::unroll(t); - if let Some(idx) = self.type_map.get(&unrolled) { - let idx = *idx; - self.type_map.insert(t.clone(), idx); - return Ok(()); - }*/ + // Disable this "optimization", as unroll is expensive and has to be called on every recursion. + // let unrolled = types::internal::unroll(t); + // if let Some(idx) = self.type_map.get(&unrolled) { + // let idx = *idx; + // self.type_map.insert(t.clone(), idx); + // return Ok(()); + // } let idx = self.type_table.len(); self.type_map.insert(t.clone(), idx as i32); diff --git a/rust/candid/src/types/internal.rs b/rust/candid/src/types/internal.rs index fe24bd95..c6d2b983 100644 --- a/rust/candid/src/types/internal.rs +++ b/rust/candid/src/types/internal.rs @@ -7,7 +7,7 @@ use std::fmt; // This is a re-implementation of std::any::TypeId to get rid of 'static constraint. // The current TypeId doesn't consider lifetime while computing the hash, which is // totally fine for Candid type, as we don't care about lifetime at all. -#[derive(Debug, PartialEq, Eq, Hash, Clone, Ord, PartialOrd)] +#[derive(Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)] pub struct TypeId { id: usize, pub name: &'static str,