Skip to content

Commit

Permalink
add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
wasm-forge committed Aug 25, 2024
1 parent adb2995 commit e1c651e
Show file tree
Hide file tree
Showing 39 changed files with 100 additions and 1,550 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
- name: Install wasi2ic
run: cargo install wasi2ic

- name: Install canbench
run: cargo install canbench

- name: Check Format
run: cargo fmt --all -- --check

Expand Down
10 changes: 6 additions & 4 deletions scripts/build_tests.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/bin/bash

cd tests/fs_benchmark_test
set -e

cd tests/canister_initial

cargo build --release --target wasm32-unknown-unknown

wasi2ic target/wasm32-unknown-unknown/release/fs_benchmark_test_backend.wasm target/wasm32-unknown-unknown/release/fs_benchmark_test_backend_small.wasm
wasi2ic target/wasm32-unknown-unknown/release/canister_initial_backend.wasm target/wasm32-unknown-unknown/release/canister_initial_backend_small.wasm

cd ../demo_test_upgraded
cd ../canister_upgraded

cargo build --release --target wasm32-unknown-unknown

wasi2ic target/wasm32-unknown-unknown/release/demo_test_upgraded_backend.wasm target/wasm32-unknown-unknown/release/demo_test_upgraded_backend_small.wasm
wasi2ic target/wasm32-unknown-unknown/release/canister_upgraded_backend.wasm target/wasm32-unknown-unknown/release/canister_upgraded_backend_small.wasm

8 changes: 5 additions & 3 deletions scripts/deploy_tests.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash

cd tests/fs_benchmark_test
set -e

dfx canister create fs_benchmark_test_backend
cd tests/canister_initial

dfx canister install --mode reinstall --wasm target/wasm32-unknown-unknown/release/fs_benchmark_test_backend_small.wasm -y fs_benchmark_test_backend
dfx canister create canister_initial_backend

dfx canister install --mode reinstall --wasm target/wasm32-unknown-unknown/release/canister_initial_backend_small.wasm -y canister_initial_backend

27 changes: 25 additions & 2 deletions src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use fns::read_text;
use pocket_ic::PocketIc;
use std::{cell::RefCell, fs};

const BACKEND_WASM: &str = "tests/fs_benchmark_test/target/wasm32-unknown-unknown/release/fs_benchmark_test_backend_small.wasm";
const BACKEND_WASM_UPGRADED: &str = "tests/demo_test_upgraded/target/wasm32-unknown-unknown/release/demo_test_upgraded_backend_small.wasm";
const BACKEND_WASM: &str = "tests/canister_initial/target/wasm32-unknown-unknown/release/canister_initial_backend_small.wasm";
const BACKEND_WASM_UPGRADED: &str = "tests/canister_upgraded/target/wasm32-unknown-unknown/release/canister_upgraded_backend_small.wasm";

thread_local!(
static ACTIVE_CANISTER: RefCell<Option<Principal>> = const { RefCell::new(None) };
Expand Down Expand Up @@ -510,3 +510,26 @@ fn large_file_write() {

assert_eq!(size, 100_000_000);
}

#[test]
fn large_file_second_write() {
let pic = setup_initial_canister();

let filename = "some_file.txt";

// create large buffer
fns::append_buffer(&pic, "abcdef7890", 10_000_000);

fns::store_buffer(&pic, filename);

let (instructions, size) = fns::store_buffer(&pic, filename);

println!("instructions {instructions}, size {size}");

assert!(
instructions < 14_000_000_000,
"The call should take less than 3 billion instructions"
);

assert_eq!(size, 100_000_000);
}
12 changes: 2 additions & 10 deletions src/storage/stable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ impl<M: Memory> ChunkPtrAllocator<M> {
}
}


struct StorageMemories<M: Memory> {
header_memory: VirtualMemory<M>,
metadata_memory: VirtualMemory<M>,
Expand All @@ -182,10 +181,8 @@ struct StorageMemories<M: Memory> {
v2_chunk_ptr_memory: VirtualMemory<M>,
v2_chunks_memory: VirtualMemory<M>,
v2_allocator_memory: VirtualMemory<M>,

}


#[repr(C)]
pub struct StableStorage<M: Memory> {
header: Cell<Header, VirtualMemory<M>>,
Expand Down Expand Up @@ -257,15 +254,10 @@ impl<M: Memory> StableStorage<M> {
v2_allocator_memory,
};

Self::new_with_custom_memories(
memories
)
Self::new_with_custom_memories(memories)
}

fn new_with_custom_memories(
memories: StorageMemories<M>

) -> Self {
fn new_with_custom_memories(memories: StorageMemories<M>) -> Self {
let default_header_value = Header {
version: FS_VERSION,
next_node: ROOT_NODE + 1,
Expand Down
2 changes: 1 addition & 1 deletion src/storage/transient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl TransientStorage {
let mut result = Self {
header: Header {
version: 1,
next_node: ROOT_NODE + 1
next_node: ROOT_NODE + 1,
},
metadata: Default::default(),
direntry: Default::default(),
Expand Down
File renamed without changes.

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

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = [
"src/fs_benchmark_test_backend"
"src/canister_initial_backend"
]
resolver = "2"

3 changes: 3 additions & 0 deletions tests/canister_initial/clear_buffer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

dfx canister call canister_initial_backend clear_buffer
5 changes: 5 additions & 0 deletions tests/canister_initial/create_buffer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

dfx canister call canister_initial_backend append_buffer '("abc1234567", 10_000_000: nat64, 100_000_000: nat64 )'


Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"canisters": {
"fs_benchmark_test_backend": {
"candid": "src/fs_benchmark_test_backend/fs_benchmark_test_backend.did",
"package": "fs_benchmark_test_backend",
"canister_initial_backend": {
"candid": "src/canister_initial_backend/canister_initial_backend.did",
"package": "canister_initial_backend",
"type": "rust"
}
},
Expand Down
3 changes: 3 additions & 0 deletions tests/canister_initial/load_buffer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

dfx canister call canister_initial_backend load_buffer '("test.txt")'
3 changes: 3 additions & 0 deletions tests/canister_initial/read_buffer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

dfx canister call canister_initial_backend read_buffer '(99999988:nat64, 10:nat64)'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "fs_benchmark_test_backend"
name = "canister_initial_backend"
version = "0.1.0"
edition = "2021"

Expand Down
3 changes: 3 additions & 0 deletions tests/canister_initial/store_buffer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

dfx canister call canister_initial_backend store_buffer '("test.txt")'
3 changes: 3 additions & 0 deletions tests/canister_initial/store_buffer_4k.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

dfx canister call canister_initial_backend store_buffer '("test.txt")'
3 changes: 3 additions & 0 deletions tests/canister_initial/store_stable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

dfx canister call canister_initial_backend store_buffer '("mount_file.txt")'
File renamed without changes.

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

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = [
"src/demo_test_upgraded_backend"
"src/canister_upgraded_backend"
]
resolver = "2"
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# demo_test_upgraded
# canister_upgraded

Welcome to your new demo_test_upgraded project and to the internet computer development community. By default, creating a new project adds this README and some template files to your project directory. You can edit these template files to customize your project and to include your own code to speed up the development cycle.
Welcome to your new canister_upgraded project and to the internet computer development community. By default, creating a new project adds this README and some template files to your project directory. You can edit these template files to customize your project and to include your own code to speed up the development cycle.

To get started, you might want to explore the project directory structure and the default configuration file. Working with this project in your development environment will not affect any production deployment or identity tokens.

To learn more before you start working with demo_test_upgraded, see the following documentation available online:
To learn more before you start working with canister_upgraded, see the following documentation available online:

- [Quick Start](https://internetcomputer.org/docs/current/developer-docs/setup/deploy-locally)
- [SDK Developer Tools](https://internetcomputer.org/docs/current/developer-docs/setup/install)
Expand All @@ -16,7 +16,7 @@ To learn more before you start working with demo_test_upgraded, see the followin
If you want to start working on your project right away, you might want to try the following commands:

```bash
cd demo_test_upgraded/
cd canister_upgraded/
dfx help
dfx canister --help
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "demo_test_upgraded_backend"
name = "canister_upgraded_backend"
version = "0.1.0"
edition = "2021"

Expand Down
3 changes: 0 additions & 3 deletions tests/fs_benchmark_test/clear_buffer.sh

This file was deleted.

5 changes: 0 additions & 5 deletions tests/fs_benchmark_test/create_buffer.sh

This file was deleted.

3 changes: 0 additions & 3 deletions tests/fs_benchmark_test/load_buffer.sh

This file was deleted.

3 changes: 0 additions & 3 deletions tests/fs_benchmark_test/read_buffer.sh

This file was deleted.

3 changes: 0 additions & 3 deletions tests/fs_benchmark_test/store_buffer.sh

This file was deleted.

3 changes: 0 additions & 3 deletions tests/fs_benchmark_test/store_buffer_4k.sh

This file was deleted.

3 changes: 0 additions & 3 deletions tests/fs_benchmark_test/store_stable.sh

This file was deleted.

1 change: 1 addition & 0 deletions tests/fs_benchmarks
Submodule fs_benchmarks added at 6a6771
2 changes: 1 addition & 1 deletion tests/perf.sh → tests/perf.repl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let file = "README.md";

let rs_config = record { start_page = 1; page_limit = 1128};

let wasm_name = "fs_benchmark_test/target/wasm32-unknown-unknown/release/fs_benchmark_test_backend_small.wasm";
let wasm_name = "canister_initial/target/wasm32-unknown-unknown/release/canister_initial_backend_small.wasm";

function perf_file_write_10mib() {
let cid = install(wasm_profiling(wasm_name, rs_config), encode (), null);
Expand Down
Loading

0 comments on commit e1c651e

Please sign in to comment.