# Best Practices for Optimizing Canister Performance

**URL:** <https://forum.dfinity.org/t/best-practices-for-optimizing-canister-performance/39455>\
**Category:** Rust\
**Created:** [December 30, 2024, 8:59am UTC](https://forum.dfinity.org/t/best-practices-for-optimizing-canister-performance/39455 "2024-12-30T08:59:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ficov12960](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ficov12960/32/21181_2.png) [@ficov12960](https://forum.dfinity.org/u/ficov12960)\
**Post date:** [December 30, 2024, 8:59am UTC](https://forum.dfinity.org/t/best-practices-for-optimizing-canister-performance/39455/1 "2024-12-30T08:59:05Z")

</div>

Hi everyone,

I’m new to working with Internet Computer canisters and would like to understand how to optimize their performance for a scalable application. I’ve noticed some latency issues in my dApp during peak traffic times, and I’m wondering if there are any specific tips or best practices for:

1. Efficient memory usage in canisters
2. Managing inter-canister calls effectively
3. Handling high volumes of user interactions

I have not found any solution. Are there any tools or techniques the community recommends for monitoring and debugging performance issues? I’m using Motoko, but I’m open to advice applicable to Rust as well.

Thanks in advance for any guidance or resources you can share!

---

<div class="post-metadata">

**Author:** ![C-B-Elite](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/c-b-elite/32/34356_2.png) [@C-B-Elite](https://forum.dfinity.org/u/C-B-Elite)\
**Post date:** [December 30, 2024, 11:02am UTC](https://forum.dfinity.org/t/best-practices-for-optimizing-canister-performance/39455/2 "2024-12-30T11:02:48Z")

</div>

> [@](#):
>
> Efficient memory usage in canisters

It is recommended to use [stable structure](https://crates.io/crates/ic-stable-structures) for stable memory. Serialization can be handled with the [bincode](https://crates.io/crates/bincode) crate, which helps manage stable memory securely and effectively.

> [@](#):
>
> Managing inter-canister calls effectively

For inter-canister calls:  
If it’s a query request within the same subnet, consider using [composite queries](https://github.com/dfinity/examples/tree/master/rust/composite_query) instead of a combination of update call + query.  
For update call + update call, you can use the cdk’s [spawn](https://docs.rs/ic-cdk/latest/ic_cdk/fn.spawn.html) method or the future crate’s [join\_all](https://github.com/dfinity/examples/tree/master/rust/parallel_calls) method to reduce latency.

> [@](#):
>
> Handling high volumes of user interactions

For handling a high volume of user interactions, when a canister processes many requests, the queue may become congested, leading to increased perceived latency for users:  
• One solution is to use the compute allocation setting in canister configurations. This increases the probability of messages in the canister’s queue being executed within each execution round, thereby accelerating the processing speed and improving perceived latency.  
•Alternatively, consider splitting operations across multiple canisters or subnets, which can reduce execution delays caused by operating within the same subnet.

> [@](#):
>
> Are there any tools or techniques the community recommends for monitoring and debugging performance issues?

For performance monitoring, the primary tool is the [instruction counter API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#system-api-performance-counter) in the [CDK](https://github.com/dfinity/cdk-rs/blob/58faf92083add2f7821e7511f468d98897542233/src/ic-cdk/src/api/mod.rs#L117). This API can analyze the number of instructions executed between two entry points.If the instruction count exceeds 5 billion, the ingress message will trigger Deterministic Time Slicing (DTS), effectively spreading execution across multiple execution rounds. This can also increase perceived latency. Reducing the number of instructions executed within a single update call can help lower latency.

You can find more information in this blog:

> **[Effective Rust canisters](https://mmapped.blog/posts/01-effective-rust-canisters)**
>
> A compilation of useful patterns for developing IC canisters in Rust.
