4 ms·
In server applications you really shouldn't use the default allocator, but have one allocator per request which can then allocate and batch-deallocate very quic
by amelius 6y ago
In server applications you really shouldn't use the default allocator, but have one allocator per request which can then allocate and batch-deallocate very quickly. Unless you want to keep objects after the request ends, of course.
- Yoric 6y agoIs that possible in Rust these days?
- Nullabillity 6y agoKind of. You can use a bump allocator like bumpalo[0], but any code that allocates needs to be aware of it (or it won't be able to take advantage of it). It also needs to reinvent all collection types (bumpalo provides strings and vectors atm). The plan is to parametrize all std collections on the allocator eventually, but that's not stable yet. [0]: https://docs.rs/bumpalo/3.6.1/bumpalo/ https://docs.rs/bumpalo/3.6.1/bumpalo/
- amelius 6y agoHopefully this project could allow allocations inside memory-mapped files (which can then later be loaded at a different base address) in one quick load operation (instead of serializing everything).
- Eikon 6y agoOr you could just use jemallocator with background threads. https://crates.io/crates/jemalloc-sys https://crates.io/crates/jemalloc-sys "background_threads (disabled by default): enables background threads by default at run-time. When set to true, background threads are created on demand (the number of background threads will be no more than the number of CPUs or active arenas). Threads run periodically, and handle purging asynchronously. [...]"
- cutemonster 6y agoWhat about an app server same process in memory cache, if using per request allocators? > keep objects after the request ends Yes. Can that be made in a way compatible with per request allocators?
- Nullabillity 6y agoDon't use the per-request allocator for those objects. You don't need to use the same allocator for everything.
- cutemonster 6y agoThat sounds great :-) Thanks