Cetra walks through what happens when you let a Rust collection choose how it gets its memory. The stable allocator interface starts with Vec and Box, which is enough to try a different strategy in one part of an application.
- Free a request’s scratch space in one go. A bump allocator hands out pieces of a larger block. When the request ends, it can reclaim the whole block at once.
- Give a component its own memory counter. A cache can evict entries based on what it allocated. Logfire uses an allocation threshold to decide when to capture a heap profile.
- Choose where the buffer lives. Small buffers can start on the stack and spill to the heap. A different allocator can provide buffers aligned for direct disk I/O.
Pick the allocator around the job the data has to do. If you’re trying to speed up request cleanup, measure peak memory alongside latency: freeing in bulk can keep temporary memory occupied longer.