Async functions and codegen

⚓ Rust    📅 2025-12-17    👤 surdeus    👁️ 1      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Async functions and codegen

Does making a function async push all the codegen to the crate calling the async function?

Background
I have a big complicated function in a crate:

// crate a
pub async fn do_lots_of_async_stuff(usize) -> usize

And then this function is called in lots of dependent crates, for example crate b:

// crate b
...
    // If the next line is commented out the compilation time for crate b decreases by 10s
    let i = do_lots_of_async_stuff(i).await;
...

So to me it seems as if a async function is not compiled once in the create wherre it is defined but leads to a whole lot of codegen in all dependent crates (in my case many).

Can this be correct? If so, is there any preferred way to work around it?

Regards

11 posts - 3 participants

Read full topic

🏷️ Rust_feed