Hacker News new | past | comments | ask | show | jobs | submit login

> I'm less familiar with Rust, but I'd have assumed trait implementations specialize there as well.

Yeah - as I understand it, traits + generics in rust monomorphize basically everything.

If anything, for rust I want the compiler to learn to do the opposite of this optimization. I'd like the compiler to be able to emit code which uses dynamic dispatch instead of monomorphization when optimizing for code size, or in cold functions. Monomorphization makes the rust compiler slower and rust binaries larger. Outside of hot loops, its often not worth it.

You can change this manually by rewriting rust functions to take dyn function pointers instead of <F: Fn> generic arguments. But I'd prefer the compiler to make that choice for me automatically based on PGO or from -Oz.




LLVM can outline code from across multiple functions at -Oz which could help.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: