Skip to content
Closed
13 changes: 10 additions & 3 deletions benchmarks/ping-pong/app/src/ping_pong_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#[allow(unused_imports)]
use sails_rs::{client::*, collections::*, prelude::*};
pub struct PingPongProgram;
impl PingPongProgram {
pub const PING_PONG_SERVICE_ROUTE_ID: u8 = 1;
}
impl sails_rs::client::Program for PingPongProgram {}
pub trait PingPong {
type Env: sails_rs::client::GearEnv;
Expand All @@ -14,7 +17,7 @@ impl<E: sails_rs::client::GearEnv> PingPong for sails_rs::client::Actor<PingPong
fn ping_pong_service(
&self,
) -> sails_rs::client::Service<ping_pong_service::PingPongServiceImpl, Self::Env> {
self.service(stringify!(PingPongService))
self.service(PingPongProgram::PING_PONG_SERVICE_ROUTE_ID)
}
}
pub trait PingPongCtors {
Expand All @@ -36,7 +39,7 @@ impl<E: sails_rs::client::GearEnv> PingPongCtors

pub mod io {
use super::*;
sails_rs::io_struct_impl!(NewForBench () -> ());
sails_rs::io_struct_impl!(NewForBench () -> (), 0);
}

pub mod ping_pong_service {
Expand All @@ -59,6 +62,10 @@ pub mod ping_pong_service {
) -> sails_rs::client::PendingCall<io::Ping, Self::Env>;
}
pub struct PingPongServiceImpl;
impl sails_rs::client::Identifiable for PingPongServiceImpl {
const INTERFACE_ID: sails_rs::InterfaceId =
sails_rs::InterfaceId::from_bytes_8([106, 114, 150, 138, 76, 98, 231, 215]);
}
impl<E: sails_rs::client::GearEnv> PingPongService
for sails_rs::client::Service<PingPongServiceImpl, E>
{
Expand All @@ -73,6 +80,6 @@ pub mod ping_pong_service {

pub mod io {
use super::*;
sails_rs::io_struct_impl!(Ping (payload: super::PingPongPayload) -> super::PingPongPayload);
sails_rs::io_struct_impl!(Ping (payload: super::PingPongPayload) -> super::PingPongPayload, 0, <super::PingPongServiceImpl as sails_rs::client::Identifiable>::INTERFACE_ID);
}
}
13 changes: 10 additions & 3 deletions benchmarks/src/alloc_stress_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#[allow(unused_imports)]
use sails_rs::{client::*, collections::*, prelude::*};
pub struct AllocStressProgram;
impl AllocStressProgram {
pub const ALLOC_STRESS_ROUTE_ID: u8 = 1;
}
impl sails_rs::client::Program for AllocStressProgram {}
pub trait AllocStress {
type Env: sails_rs::client::GearEnv;
Expand All @@ -10,7 +13,7 @@ pub trait AllocStress {
impl<E: sails_rs::client::GearEnv> AllocStress for sails_rs::client::Actor<AllocStressProgram, E> {
type Env = E;
fn alloc_stress(&self) -> sails_rs::client::Service<alloc_stress::AllocStressImpl, Self::Env> {
self.service(stringify!(AllocStress))
self.service(AllocStressProgram::ALLOC_STRESS_ROUTE_ID)
}
}
pub trait AllocStressCtors {
Expand All @@ -32,7 +35,7 @@ impl<E: sails_rs::client::GearEnv> AllocStressCtors

pub mod io {
use super::*;
sails_rs::io_struct_impl!(NewForBench () -> ());
sails_rs::io_struct_impl!(NewForBench () -> (), 0);
}

pub mod alloc_stress {
Expand All @@ -52,6 +55,10 @@ pub mod alloc_stress {
) -> sails_rs::client::PendingCall<io::AllocStress, Self::Env>;
}
pub struct AllocStressImpl;
impl sails_rs::client::Identifiable for AllocStressImpl {
const INTERFACE_ID: sails_rs::InterfaceId =
sails_rs::InterfaceId::from_bytes_8([9, 48, 193, 195, 84, 117, 173, 52]);
}
impl<E: sails_rs::client::GearEnv> AllocStress for sails_rs::client::Service<AllocStressImpl, E> {
type Env = E;
fn alloc_stress(
Expand All @@ -64,6 +71,6 @@ pub mod alloc_stress {

pub mod io {
use super::*;
sails_rs::io_struct_impl!(AllocStress (n: u32) -> super::AllocStressResult);
sails_rs::io_struct_impl!(AllocStress (n: u32) -> super::AllocStressResult, 0, <super::AllocStressImpl as sails_rs::client::Identifiable>::INTERFACE_ID);
}
}
64 changes: 39 additions & 25 deletions benchmarks/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@
//! ```

use crate::clients::{
alloc_stress_client::{AllocStress as _, AllocStressCtors, alloc_stress::*},
compute_stress_client::{ComputeStress as _, ComputeStressCtors, compute_stress::*},
counter_bench_client::{CounterBench as _, CounterBenchCtors, counter_bench::*},
alloc_stress_client::{
AllocStress as _, AllocStressCtors, AllocStressProgram, alloc_stress::*,
},
compute_stress_client::{
ComputeStress as _, ComputeStressCtors, ComputeStressProgram, compute_stress::*,
},
counter_bench_client::{
CounterBench as _, CounterBenchCtors, CounterBenchProgram, counter_bench::*,
},
};
use gtest::{System, constants::DEFAULT_USER_ALICE};
use itertools::{Either, Itertools};
use ping_pong_bench_app::client::{PingPong, PingPongCtors, ping_pong_service::*};
use ping_pong_bench_app::client::{PingPong, PingPongCtors, PingPongProgram, ping_pong_service::*};
use redirect_client::{RedirectClient, RedirectClientCtors, redirect::*};
use redirect_proxy_client::{RedirectProxyClient, RedirectProxyClientCtors, proxy::*};
use redirect_proxy_client::{
RedirectProxyClient, RedirectProxyClientCtors, RedirectProxyClientProgram, proxy::*,
};
use sails_rs::{client::*, prelude::*};
use std::{collections::BTreeMap, sync::atomic::AtomicU64};

Expand Down Expand Up @@ -67,11 +75,10 @@ async fn compute_stress_bench() {
.map(|_| {
let message_id = service.compute_stress(input_value).send_one_way().unwrap();
let (payload, gas) = extract_reply_and_gas(env.system(), message_id);
let stress_resp = crate::clients::compute_stress_client::compute_stress::io::ComputeStress::decode_reply_with_prefix(
"ComputeStress",
payload.as_slice(),
)
.unwrap();
// Low-level approach: decoding using generated io module
let stress_resp =
crate::clients::compute_stress_client::compute_stress::io::ComputeStress::decode_reply(ComputeStressProgram::COMPUTE_STRESS_ROUTE_ID, payload.as_slice())
.unwrap();
assert_eq!(stress_resp.res, expected_sum);
gas
})
Expand Down Expand Up @@ -99,8 +106,9 @@ async fn counter_bench() {
let gas = if is_sync {
let message_id = service.inc().send_one_way().unwrap();
let (payload, gas) = extract_reply_and_gas(env.system(), message_id);
let stress_resp = crate::clients::counter_bench_client::counter_bench::io::Inc::decode_reply_with_prefix(
"CounterBench",
// Low-level approach: decoding using generated io module
let stress_resp = crate::clients::counter_bench_client::counter_bench::io::Inc::decode_reply(
CounterBenchProgram::COUNTER_BENCH_ROUTE_ID,
payload.as_slice(),
)
.unwrap();
Expand All @@ -111,8 +119,9 @@ async fn counter_bench() {
} else {
let message_id = service.inc_async().send_one_way().unwrap();
let (payload, gas) = extract_reply_and_gas(env.system(), message_id);
let stress_resp = crate::clients::counter_bench_client::counter_bench::io::IncAsync::decode_reply_with_prefix(
"CounterBench",
// Low-level approach: decoding using generated io module
let stress_resp = crate::clients::counter_bench_client::counter_bench::io::IncAsync::decode_reply(
CounterBenchProgram::COUNTER_BENCH_ROUTE_ID,
payload.as_slice(),
)
.unwrap();
Expand Down Expand Up @@ -158,9 +167,10 @@ async fn cross_program_bench() {
.send_one_way()
.unwrap();
let (payload, gas) = extract_reply_and_gas(env.system(), message_id);
// Low-level approach: decoding using generated io module
let stress_resp =
ping_pong_bench_app::client::ping_pong_service::io::Ping::decode_reply_with_prefix(
"PingPongService",
ping_pong_bench_app::client::ping_pong_service::io::Ping::decode_reply(
PingPongProgram::PING_PONG_SERVICE_ROUTE_ID,
payload.as_slice(),
)
.unwrap();
Expand Down Expand Up @@ -199,8 +209,9 @@ async fn redirect_bench() {
.send_one_way()
.unwrap();
let (payload, _gas) = extract_reply_and_gas(env.system(), message_id);
let resp = redirect_proxy_client::proxy::io::GetProgramId::decode_reply_with_prefix(
"Proxy",
// Low-level approach: decoding using generated io module
let resp = redirect_proxy_client::proxy::io::GetProgramId::decode_reply(
RedirectProxyClientProgram::PROXY_ROUTE_ID,
payload.as_slice(),
)
.unwrap();
Expand All @@ -223,8 +234,9 @@ async fn redirect_bench() {
.send_one_way()
.unwrap();
let (payload, gas) = extract_reply_and_gas(env.system(), message_id);
let resp = redirect_proxy_client::proxy::io::GetProgramId::decode_reply_with_prefix(
"Proxy",
// Low-level approach: decoding using generated io module
let resp = redirect_proxy_client::proxy::io::GetProgramId::decode_reply(
RedirectProxyClientProgram::PROXY_ROUTE_ID,
payload.as_slice(),
)
.unwrap();
Expand Down Expand Up @@ -269,11 +281,13 @@ async fn alloc_stress_test(n: u32) -> (usize, u64) {
let mut service = program.alloc_stress();
let message_id = service.alloc_stress(n).send_one_way().unwrap();
let (payload, gas) = extract_reply_and_gas(env.system(), message_id);
let stress_resp = crate::clients::alloc_stress_client::alloc_stress::io::AllocStress::decode_reply_with_prefix(
"AllocStress",
payload.as_slice(),
)
.unwrap();
// Low-level approach: decoding using generated io module
let stress_resp =
crate::clients::alloc_stress_client::alloc_stress::io::AllocStress::decode_reply(
AllocStressProgram::ALLOC_STRESS_ROUTE_ID,
payload.as_slice(),
)
.unwrap();

let expected_len = alloc_stress::fibonacci_sum(n) as usize;
assert_eq!(stress_resp.inner.len(), expected_len);
Expand Down
13 changes: 10 additions & 3 deletions benchmarks/src/compute_stress_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#[allow(unused_imports)]
use sails_rs::{client::*, collections::*, prelude::*};
pub struct ComputeStressProgram;
impl ComputeStressProgram {
pub const COMPUTE_STRESS_ROUTE_ID: u8 = 1;
}
impl sails_rs::client::Program for ComputeStressProgram {}
pub trait ComputeStress {
type Env: sails_rs::client::GearEnv;
Expand All @@ -16,7 +19,7 @@ impl<E: sails_rs::client::GearEnv> ComputeStress
fn compute_stress(
&self,
) -> sails_rs::client::Service<compute_stress::ComputeStressImpl, Self::Env> {
self.service(stringify!(ComputeStress))
self.service(ComputeStressProgram::COMPUTE_STRESS_ROUTE_ID)
}
}
pub trait ComputeStressCtors {
Expand All @@ -38,7 +41,7 @@ impl<E: sails_rs::client::GearEnv> ComputeStressCtors

pub mod io {
use super::*;
sails_rs::io_struct_impl!(NewForBench () -> ());
sails_rs::io_struct_impl!(NewForBench () -> (), 0);
}

pub mod compute_stress {
Expand All @@ -58,6 +61,10 @@ pub mod compute_stress {
) -> sails_rs::client::PendingCall<io::ComputeStress, Self::Env>;
}
pub struct ComputeStressImpl;
impl sails_rs::client::Identifiable for ComputeStressImpl {
const INTERFACE_ID: sails_rs::InterfaceId =
sails_rs::InterfaceId::from_bytes_8([254, 138, 70, 56, 122, 195, 121, 54]);
}
impl<E: sails_rs::client::GearEnv> ComputeStress
for sails_rs::client::Service<ComputeStressImpl, E>
{
Expand All @@ -72,6 +79,6 @@ pub mod compute_stress {

pub mod io {
use super::*;
sails_rs::io_struct_impl!(ComputeStress (n: u32) -> super::ComputeStressResult);
sails_rs::io_struct_impl!(ComputeStress (n: u32) -> super::ComputeStressResult, 0, <super::ComputeStressImpl as sails_rs::client::Identifiable>::INTERFACE_ID);
}
}
15 changes: 11 additions & 4 deletions benchmarks/src/counter_bench_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#[allow(unused_imports)]
use sails_rs::{client::*, collections::*, prelude::*};
pub struct CounterBenchProgram;
impl CounterBenchProgram {
pub const COUNTER_BENCH_ROUTE_ID: u8 = 1;
}
impl sails_rs::client::Program for CounterBenchProgram {}
pub trait CounterBench {
type Env: sails_rs::client::GearEnv;
Expand All @@ -16,7 +19,7 @@ impl<E: sails_rs::client::GearEnv> CounterBench
fn counter_bench(
&self,
) -> sails_rs::client::Service<counter_bench::CounterBenchImpl, Self::Env> {
self.service(stringify!(CounterBench))
self.service(CounterBenchProgram::COUNTER_BENCH_ROUTE_ID)
}
}
pub trait CounterBenchCtors {
Expand All @@ -38,7 +41,7 @@ impl<E: sails_rs::client::GearEnv> CounterBenchCtors

pub mod io {
use super::*;
sails_rs::io_struct_impl!(NewForBench () -> ());
sails_rs::io_struct_impl!(NewForBench () -> (), 0);
}

pub mod counter_bench {
Expand All @@ -49,6 +52,10 @@ pub mod counter_bench {
fn inc_async(&mut self) -> sails_rs::client::PendingCall<io::IncAsync, Self::Env>;
}
pub struct CounterBenchImpl;
impl sails_rs::client::Identifiable for CounterBenchImpl {
const INTERFACE_ID: sails_rs::InterfaceId =
sails_rs::InterfaceId::from_bytes_8([149, 170, 24, 82, 218, 19, 238, 13]);
}
impl<E: sails_rs::client::GearEnv> CounterBench for sails_rs::client::Service<CounterBenchImpl, E> {
type Env = E;
fn inc(&mut self) -> sails_rs::client::PendingCall<io::Inc, Self::Env> {
Expand All @@ -61,7 +68,7 @@ pub mod counter_bench {

pub mod io {
use super::*;
sails_rs::io_struct_impl!(Inc () -> u64);
sails_rs::io_struct_impl!(IncAsync () -> u64);
sails_rs::io_struct_impl!(Inc () -> u64, 0, <super::CounterBenchImpl as sails_rs::client::Identifiable>::INTERFACE_ID);
sails_rs::io_struct_impl!(IncAsync () -> u64, 1, <super::CounterBenchImpl as sails_rs::client::Identifiable>::INTERFACE_ID);
}
}
9 changes: 6 additions & 3 deletions examples/demo/app/tests/gclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async fn ping_pong_works() {
// Use generated `io` module for encoding/decoding calls and replies
// and send/receive bytes using `gclient` native means (env is just a wrapper)
let ping_call_payload =
ping_pong::io::Ping::encode_params_with_prefix("PingPong", "ping".into());
ping_pong::io::Ping::encode_call(DemoClientProgram::PING_PONG_ROUTE_ID, "ping".into());

// Act
let ping_reply_payload = env
Expand All @@ -124,8 +124,11 @@ async fn ping_pong_works() {
.await
.unwrap();

let ping_reply =
ping_pong::io::Ping::decode_reply_with_prefix("PingPong", ping_reply_payload).unwrap();
let ping_reply = ping_pong::io::Ping::decode_reply(
DemoClientProgram::PING_PONG_ROUTE_ID,
ping_reply_payload,
)
.unwrap();

// Assert

Expand Down
Loading
Loading