-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
moka is too polymorphic (cargo-llvm-lines) #203
Comments
looks like I was a bit overeager. Apart from the one I found, most of the things are either due explicit |
I’m been playing a bit with this, trying to create a stresstest aimed at getting a hold of the compile times. use moka::future::Cache;
macro_rules! generate {
($($n:ident: $a:ty => $b: ty,)+) => {
struct State {
$($n: Cache<$a, $b>,)+
}
impl State {
fn new() -> Self {
Self {
$($n: Cache::builder().build(),)+
}
}
$(async fn $n(&self, k: $a) -> $b {
self.$n.get_with(k, async { 1 }).await
})+
}
fn main() {
let state = State::new();
let sum = futures_executor::block_on(async {
let mut sum = 0;
$(sum += state.$n(0).await as u64;)+
sum
});
println!("{sum}");
}
};
}
generate!(
cache_u8_u8: u8 => u8,
cache_u8_u16: u8 => u16,
cache_u8_u32: u8 => u32,
cache_u8_u64: u8 => u64,
cache_u16_u8: u16 => u8,
cache_u16_u16: u16 => u16,
cache_u16_u32: u16 => u32,
cache_u16_u64: u16 => u64,
cache_u32_u8: u32 => u8,
cache_u32_u16: u32 => u16,
cache_u32_u32: u32 => u32,
cache_u32_u64: u32 => u64,
cache_u64_u8: u64 => u8,
cache_u64_u16: u64 => u16,
cache_u64_u32: u64 => u32,
cache_u64_u64: u64 => u64,
); This testcase will generate up to 16 different instantiations of On my Windows system, I see a compile-time ( A run of
Using
I think most of the methods actually do need to have 16 different variants, though internally it might be a good idea to deduplicate some things. |
A quick check with my #265 PR: A debug build with 16 versions take ~9s, and a release build ~21s, so not that much of a difference.
Interestingly,
|
great work |
I was playing around with https://github.com/dtolnay/cargo-llvm-lines recently, and found out that
moka
does generate a ton of llvm IR due to too much internal generics.This is suboptimal for a couple of reasons:
Running
cargo-llvm-lines
on a small test program:gives me this these functions on the top:
You can see that some functions are duplicated as often as 21 times.
I do have some ideas to reduce this bloat, so watch out for some patches ;-)
The text was updated successfully, but these errors were encountered: