Skip to content

Commit

Permalink
Release 0.44.0 (#659)
Browse files Browse the repository at this point in the history
* Release 0.44.0

* Combine BytesVisitor and ArrayVisitor

* Fix alloc feature imports

* Add key! serde benchmarks

* Fixed benchmarks improved the result for bincode

* Fixed wrong deserialization in benchmarks

* Run publish check

* Run it each PR

---------

Co-authored-by: xgreenx <xgreenx9999@gmail.com>
  • Loading branch information
Dentosal and xgreenx authored Jan 22, 2024
1 parent f8f2c68 commit db87869
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 55 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ jobs:
- rustfmt
- cargo
- cargo-toml-fmt-check
- publish-check
runs-on: ubuntu-latest
steps:
- run: true

publish-check:
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -153,15 +153,14 @@ jobs:
toolchain: ${{ env.RUST_VERSION }}

- name: Publish crate check
uses: katyo/publish-crates@v2
uses: xgreenx/publish-crates@v1
with:
dry-run: true

publish:
# Only do this job if publishing a release and all checks pass.
needs:
- verifications-complete
- publish-check
if: github.event_name == 'release' && github.event.action == 'published'
runs-on: buildjet-4vcpu-ubuntu-2204

Expand All @@ -178,7 +177,7 @@ jobs:
./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} Cargo.toml
- name: Publish crate
uses: katyo/publish-crates@v2
uses: xgreenx/publish-crates@v1
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [Version 0.44.0]

#### Changed

- [#653](https://github.com/FuelLabs/fuel-vm/pull/653): `ECAL` opcode handler can now hold internal state.
Expand Down
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ edition = "2021"
homepage = "https://fuel.network/"
license = "BUSL-1.1"
repository = "https://github.com/FuelLabs/fuel-vm"
version = "0.43.2"
version = "0.44.0"

[workspace.dependencies]
fuel-asm = { version = "0.43.2", path = "fuel-asm", default-features = false }
fuel-crypto = { version = "0.43.2", path = "fuel-crypto", default-features = false }
fuel-derive = { version = "0.43.2", path = "fuel-derive", default-features = false }
fuel-merkle = { version = "0.43.2", path = "fuel-merkle", default-features = false }
fuel-storage = { version = "0.43.2", path = "fuel-storage", default-features = false }
fuel-tx = { version = "0.43.2", path = "fuel-tx", default-features = false }
fuel-types = { version = "0.43.2", path = "fuel-types", default-features = false }
fuel-vm = { version = "0.43.2", path = "fuel-vm", default-features = false }
fuel-asm = { version = "0.44.0", path = "fuel-asm", default-features = false }
fuel-crypto = { version = "0.44.0", path = "fuel-crypto", default-features = false }
fuel-derive = { version = "0.44.0", path = "fuel-derive", default-features = false }
fuel-merkle = { version = "0.44.0", path = "fuel-merkle", default-features = false }
fuel-storage = { version = "0.44.0", path = "fuel-storage", default-features = false }
fuel-tx = { version = "0.44.0", path = "fuel-tx", default-features = false }
fuel-types = { version = "0.44.0", path = "fuel-types", default-features = false }
fuel-vm = { version = "0.44.0", path = "fuel-vm", default-features = false }
bitflags = "2"
bincode = { version = "1.3", default-features = false }
criterion = "0.5.0"
Expand Down
64 changes: 61 additions & 3 deletions fuel-types/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use criterion::{
black_box,
criterion_group,
criterion_main,
Criterion,
};
use fuel_types::{
canonical,
canonical::Serialize,
Bytes64,
};

#[cfg(feature = "unsafe")]
use criterion::black_box;
#[cfg(feature = "unsafe")]
use fuel_types::bytes::from_slice_unchecked;

Expand Down Expand Up @@ -106,5 +110,59 @@ pub fn criterion_benchmark(c: &mut Criterion) {
}
}

criterion_group!(benches, criterion_benchmark);
pub fn criterion_benchmark2(c: &mut Criterion) {
use fuel_types::Bytes32;

c.bench_function("serde_bincode_key_roundtrip_32", |b| {
let original = black_box(Bytes32::from([1u8; 32]));
b.iter(|| {
let serialized = black_box(bincode::serialize(&original)).unwrap();
let _: Bytes32 = black_box(bincode::deserialize(&serialized)).unwrap();
});
});

c.bench_function("serde_bincode_key_roundtrip_64", |b| {
let original = black_box(Bytes64::from([1u8; 64]));
b.iter(|| {
let serialized = black_box(bincode::serialize(&original)).unwrap();
let _: Bytes64 = black_box(bincode::deserialize(&serialized)).unwrap();
});
});

c.bench_function("serde_postcard_key_roundtrip_32", |b| {
let original = black_box(Bytes32::from([1u8; 32]));
b.iter(|| {
let serialized = black_box(postcard::to_stdvec(&original)).unwrap();
let _: Bytes32 = black_box(postcard::from_bytes(&serialized)).unwrap();
});
});

c.bench_function("serde_postcard_key_roundtrip_64", |b| {
let original = black_box(Bytes64::from([1u8; 64]));
b.iter(|| {
let serialized = black_box(postcard::to_stdvec(&original)).unwrap();
let _: Bytes64 = black_box(postcard::from_bytes(&serialized)).unwrap();
});
});

c.bench_function("canonical_key_roundtrip_32", |b| {
let original = black_box(Bytes32::from([1u8; 32]));
b.iter(|| {
let serialized = black_box(original.to_bytes());
let _: Bytes32 =
black_box(canonical::Deserialize::from_bytes(&serialized)).unwrap();
});
});

c.bench_function("canonical_key_roundtrip_64", |b| {
let original = black_box(Bytes64::from([1u8; 64]));
b.iter(|| {
let serialized = black_box(original.to_bytes());
let _: Bytes64 =
black_box(canonical::Deserialize::from_bytes(&serialized)).unwrap();
});
});
}

criterion_group!(benches, criterion_benchmark, criterion_benchmark2);
criterion_main!(benches);
70 changes: 31 additions & 39 deletions fuel-types/src/array_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ macro_rules! key_methods {

#[cfg(feature = "serde")]
impl serde::Serialize for $i {
#[inline(always)]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
Expand All @@ -326,7 +327,7 @@ macro_rules! key_methods {
serializer.serialize_str(&format!("{:x}", &self))
} else {
// Fixed-size arrays are tuples in serde data model
let mut arr = serializer.serialize_tuple(self.0.len())?;
let mut arr = serializer.serialize_tuple($s)?;
for elem in &self.0 {
arr.serialize_element(elem)?;
}
Expand All @@ -337,51 +338,18 @@ macro_rules! key_methods {

#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for $i {
#[inline(always)]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
use serde::de::{
self,
Error,
Visitor,
};
use serde::de::Error;
if deserializer.is_human_readable() {
let s: alloc::string::String =
serde::Deserialize::deserialize(deserializer)?;
s.parse().map_err(D::Error::custom)
} else {
/// This is what serde needs to deserialize a fixed-size array
pub struct ArrayVisitor;
impl<'de> Visitor<'de> for ArrayVisitor {
type Value = [u8; $s];

fn expecting(
&self,
formatter: &mut fmt::Formatter,
) -> fmt::Result {
formatter.write_str("a byte array")
}

fn visit_seq<A>(
self,
mut value: A,
) -> Result<Self::Value, A::Error>
where
A: de::SeqAccess<'de>,
{
let mut arr = [0u8; $s];
for (i, elem) in arr.iter_mut().enumerate() {
*elem = value
.next_element()?
.ok_or_else(|| de::Error::invalid_length(i, &self))?;
}
Ok(arr)
}
}
let arr = deserializer.deserialize_tuple($s, ArrayVisitor)?;

Ok(Self(arr))
deserializer.deserialize_tuple($s, ArrayVisitor).map(Self)
}
}
}
Expand Down Expand Up @@ -422,21 +390,45 @@ impl From<u64> for Nonce {

/// A visitor for deserializing a fixed-size byte array.
#[cfg(feature = "serde")]
struct BytesVisitor<const S: usize>;
struct ArrayVisitor<const S: usize>;

#[cfg(feature = "serde")]
impl<'de, const S: usize> serde::de::Visitor<'de> for BytesVisitor<S> {
impl<'de, const S: usize> serde::de::Visitor<'de> for ArrayVisitor<S> {
type Value = [u8; S];

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "an array of {S} bytes")
}

#[inline(always)]
fn visit_borrowed_bytes<E>(self, items: &'de [u8]) -> Result<Self::Value, E> {
let mut result = [0u8; S];
result.copy_from_slice(items);
Ok(result)
}

#[cfg(feature = "alloc")]
#[inline(always)]
fn visit_byte_buf<E>(self, v: alloc::vec::Vec<u8>) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
self.visit_borrowed_bytes(v.as_slice())
}

#[inline(always)]
fn visit_seq<A>(self, mut value: A) -> Result<Self::Value, A::Error>
where
A: serde::de::SeqAccess<'de>,
{
let mut arr = [0u8; S];
for (i, elem) in arr.iter_mut().enumerate() {
*elem = value
.next_element()?
.ok_or_else(|| serde::de::Error::invalid_length(i, &self))?;
}
Ok(arr)
}
}

/// Roundtrip serde encode/decode tests
Expand Down

0 comments on commit db87869

Please sign in to comment.