You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This deterministic layout enables powerful optimizations but also creates strict performance constraints.
190
+
191
+
> Solana imposes strict memory limitations: 4KB stack frames per function call and 32KB total heap space per program execution.
192
+
193
+
### The Zero-Allocation Advantage
194
+
195
+
Pinocchio's main performance breakthrough comes from using references instead of heap allocations for everything.
196
+
197
+
This approach leverages a key insight: **the SVM already loads all your program inputs into memory**, so copying that data into new heap allocations is pure waste.
198
+
199
+
Heap allocation isn't inherently bad, but on Solana it's expensive and complex because every allocation consumes precious compute units: each allocation fragments the limited heap space and cleanup operations consume additional compute units.
200
+
201
+
### Zero-Allocation Techniques
202
+
203
+
1. Reference-Based Data Structures - Transform owned data into borrowed references:
// Enforces no-std to prevents accidental heap usage:
234
+
#![no_std]
235
+
```
236
+
237
+
### Pinocchio Memory Allocator
238
+
239
+
If you want to make sure that you don't allocate any heap, Pinocchio provide a specialized macro to make sure that this happen: `no_allocator!()`
240
+
241
+
> If not set, Pinocchio will use the `default_allocator!()` for programs requiring traditional heap operations.
242
+
243
+
Other than this, you can always write a better heap allocator that knows how to clean up after itself. If you're interested in this approach, [here's an example](https://github.com/solana-labs/solana-program-library/blob/master/examples/rust/custom-heap/src/entrypoint.rs).
0 commit comments