Recently I have been spending a lot of time analyzing and optimizing memory usage in our Rust reverse-proxy, agentgateway. One thing that repeatedly came up was a surprisingly large amount of memory allocated to innocent-looking Tokio mpsc channels. In my naive understanding, I would have assumed the following allocation pattern: struct BigStruct { data: [u8; 1024], } fn main() { // Allocates ~1024 bytes let _ = tokio::sync::mpsc::channel::<BigStruct>(1); // Allocates ~1024*1024 bytes let _ = tokio::sync::mpsc::channel::<BigStruct>(1024); } However, in practice both of these are wrong: they each allocate 32kb!
No comments yet. Log in to reply on the Fediverse. Comments will appear here.