actor A {
public shared func f(): async () {
await B.g();
}
}
actor B {
public shared func g(): async () {
await C.h();
}
}
actor C {
public shared func h(): async () {}
}
Is the latency of calling A.f about two times (because of two awaits) above the latency of calling B.g or is about the same (constituting a single rendezvous of two awaits?)? (Assume that network is infinitely fast.)
As the following experiment seems to prove, the time for one rendezvous and 20 consecutive rendezvouses is almost the same.
actor A {
public shared func f(times: Nat): async () {
if (times == 0) return;
await A.f(times - 1);
};
}
dfx deploy
dfx ledger fabricate-cycles --amount 1000000000 --canister A
time for i in `seq 20`; do dfx canister call A f '(20)'; done
real 0m34.313s
user 0m0.388s
sys 0m0.114s
time for i in `seq 20`; do dfx canister call A f '(1)'; done
real 0m33.990s
user 0m0.344s
sys 0m0.164s
When I add --artificial-delay 2000 to dfx start, the measurements become:
time for i in `seq 20`; do dfx canister call A f '(20)'; done
real 1m22.212s
user 0m0.643s
sys 0m0.125s
time for i in `seq 20`; do dfx canister call A f '(1)'; done
real 1m20.884s
user 0m0.563s
sys 0m0.123s
The scheduler is smart. If there is little enough traffic it can run the next message (the one you’re awaiting) in the same round, so you won’t waste time unnecessarily