Skip to content

Commit

Permalink
Merge branch 'ulan/exc-919' into 'master'
Browse files Browse the repository at this point in the history
EXC-919: Replace cbor_serde with bincode in sandboxing IPC

The cbor_serde does not support i128/u128 and is not maintained.
This MR switches the sandboxing IPC to bincode.

Performance of the system API benchmark improves up to 60%. 

See merge request dfinity-lab/public/ic!3282
  • Loading branch information
ulan committed Feb 23, 2022
2 parents f4e2634 + e5ff45f commit 45b340a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rs/Cargo.lock

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

2 changes: 1 addition & 1 deletion rs/canister_sandbox/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ name = "test_sandbox"
path = "src/test_sandbox.rs"

[dependencies]
bincode = "1.2.1"
bytes = "1.0.1"
serde_bytes = "0.11"
serde_cbor = "0.11.1"
ic-embedders = { path = "../../embedders" }
ic-interfaces = { path = "../../interfaces" }
ic-replicated-state = { path = "../../replicated_state" }
Expand Down
5 changes: 1 addition & 4 deletions rs/canister_sandbox/common/src/frame_decoder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bytes::{Buf, BytesMut};
use serde::de::DeserializeOwned;
use serde_cbor::Deserializer;
use std::marker::PhantomData;

/// Incremental decoder for stream of data. Splits frames preceded by
Expand Down Expand Up @@ -51,9 +50,7 @@ impl<Message: DeserializeOwned + Clone> FrameDecoder<Message> {
let frame = data.split_to(size);
self.state = FrameDecoderState::NoLength;
let frame = frame.clone();
let mut deserializer = Deserializer::from_slice(&frame);
let value: Result<Message, _> =
serde::de::Deserialize::deserialize(&mut deserializer);
let value: Result<Message, _> = bincode::deserialize(&frame);

if value.is_err() {
continue;
Expand Down
2 changes: 1 addition & 1 deletion rs/canister_sandbox/common/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl<
let fds: Vec<RawFd> = fd_locs.iter().map(|fd| **fd).collect();

// Serialize the message.
let serialized_msg = serde_cbor::to_vec(&msg).expect("Failed to serialize message");
let serialized_msg = bincode::serialize(&msg).expect("Failed to serialize message");

// Send message data + file descriptors down.
// There must be a field in the struct for every file descriptor
Expand Down
30 changes: 30 additions & 0 deletions rs/execution_environment/testgrid/common/hypervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5051,3 +5051,33 @@ fn can_extract_exported_custom_sections() {
assert_eq!(execution_state.metadata.custom_sections().len(), 3);
});
}

#[test]
fn execute_with_huge_cycle_balance() {
with_hypervisor(|hypervisor, tmp_path| {
let wasm = wabt::wat2wasm(
r#"
(module
(func (export "canister_init"))
(memory 0))
"#,
)
.unwrap();

let canister_id = canister_test_id(42);
let execution_state = hypervisor
.create_execution_state(wasm, tmp_path, canister_id)
.unwrap();
let mut canister = canister_from_exec_state(execution_state, canister_id);
let execution_parameters = execution_parameters(&canister, MAX_NUM_INSTRUCTIONS);
*canister.system_state.balance_mut() = Cycles::new(1u128 << 100);
let (_, _, res) = hypervisor.execute_canister_init(
canister,
test_caller(),
EMPTY_PAYLOAD.as_slice(),
mock_time(),
execution_parameters,
);
assert!(res.is_ok());
});
}

0 comments on commit 45b340a

Please sign in to comment.