Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request paritytech#224 from subspace/archiving-optimizations
Browse files Browse the repository at this point in the history
Archiving optimizations
  • Loading branch information
nazar-pc authored Jan 3, 2022
2 parents 734c6b7 + 77a8246 commit 35cf6f5
Show file tree
Hide file tree
Showing 11 changed files with 338 additions and 75 deletions.
131 changes: 131 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ sha3 = { opt-level = 3 }
sloth256-189 = { opt-level = 3 }
smallvec = { opt-level = 3 }
snow = { opt-level = 3 }
subspace-core-primitives = { opt-level = 3 }
subspace-archiving = { opt-level = 3 }
twox-hash = { opt-level = 3 }
uint = { opt-level = 3 }
wasmi = { opt-level = 3 }
Expand Down
4 changes: 2 additions & 2 deletions crates/sc-consensus-subspace/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use std::sync::Arc;
use std::{cell::RefCell, task::Poll, time::Duration};
use subspace_archiving::archiver::Archiver;
use subspace_core_primitives::objects::BlockObjectMapping;
use subspace_core_primitives::{FlatPieces, LocalChallenge, Piece, Signature, Tag, PIECE_SIZE};
use subspace_core_primitives::{FlatPieces, LocalChallenge, Piece, Signature, Tag};
use subspace_solving::{SubspaceCodec, SOLUTION_SIGNING_CONTEXT};
use substrate_test_runtime::{Block as TestBlock, Hash};

Expand Down Expand Up @@ -538,7 +538,7 @@ fn run_one_test(mutator: impl Fn(&mut TestHeader, Stage) + Send + Sync + 'static
.await
.unwrap()
.iter()
.flat_map(|flat_pieces| flat_pieces.chunks_exact(PIECE_SIZE))
.flat_map(|flat_pieces| flat_pieces.as_pieces())
.enumerate()
.choose(&mut rand::thread_rng())
.map(|(piece_index, piece)| (piece_index as u64, Piece::try_from(piece).unwrap()))
Expand Down
6 changes: 6 additions & 0 deletions crates/subspace-archiving/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.1.0"
authors = ["Nazar Mokrynskyi <nazar@mokrynskyi.com>"]
edition = "2021"
include = [
"/benches",
"/src",
"/Cargo.toml",
"/README.md",
Expand All @@ -32,6 +33,7 @@ default-features = false
version = "0.10.0"

[dev-dependencies]
criterion = "0.3.5"
rand = { version = "0.8.4", features = ["min_const_gen"] }

[features]
Expand All @@ -44,3 +46,7 @@ std = [
"subspace-core-primitives/std",
"thiserror",
]

[[bench]]
name = "archiving"
harness = false
31 changes: 31 additions & 0 deletions crates/subspace-archiving/benches/archiving.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#![feature(int_log)]

use criterion::{criterion_group, criterion_main, Criterion};
use subspace_archiving::archiver::Archiver;
use subspace_core_primitives::{PIECE_SIZE, SHA256_HASH_SIZE};

const MERKLE_NUM_LEAVES: u32 = 256;
const WITNESS_SIZE: u32 = SHA256_HASH_SIZE as u32 * MERKLE_NUM_LEAVES.log2();
pub const RECORD_SIZE: u32 = PIECE_SIZE as u32 - WITNESS_SIZE;
pub const RECORDED_HISTORY_SEGMENT_SIZE: u32 = RECORD_SIZE * MERKLE_NUM_LEAVES / 2;

pub fn criterion_benchmark(c: &mut Criterion) {
let mut input = Vec::<u8>::with_capacity(RECORDED_HISTORY_SEGMENT_SIZE.try_into().unwrap());
input.resize(input.capacity(), 1);

c.bench_function("archiving-2-blocks", |b| {
b.iter(|| {
let mut archiver = Archiver::new(
RECORD_SIZE.try_into().unwrap(),
RECORDED_HISTORY_SEGMENT_SIZE.try_into().unwrap(),
)
.unwrap();
for _ in 0..2 {
archiver.add_block(input.clone(), Default::default());
}
})
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
Loading

0 comments on commit 35cf6f5

Please sign in to comment.