News for hackers. Stuff that matters.
Re:Rust is now overall faster than C in benchmarks by pbadenski on Monday January 04, 2021 @04:50AM (#25629316)
Thank you for mentioning monomorphization - I wasn't aware of this concept.

Would you maybe if there's any source discussing how this is solved in different languages and performance consequences of it?

Re:Rust is now overall faster than C in benchmarks by bicolao on Monday January 04, 2021 @06:18AM (#25629915)
Not really answering your questions, but regarding monomorphization, you can see a comparison of code size and compilation speed between printf, std::format and C++ iostream. The last one is monomophization, I believe.

https://github.com/fmtlib/fmt#compile-time-and-code-bloat

Re:Rust is now overall faster than C in benchmarks by scottlamb on Monday January 04, 2021 @12:11PM (#25634363)
I'm not aware of a high-quality source discussing this. I'd be interested in seeing one. Off the top of my head:

* In many languages, monomorphization is impractical. Eg, in C it requires macros or external code generators. Java and Go don't even have macros. So it's rarely done. Instead, stuff uses type erasure, dynamic dispatch, more heap allocations, and tables like the ones described in that dave.cheney.net link. Maybe some JITs or even some ahead-of-time compilers do monomorphization internally in some cases, but I'm speculating rather than speaking from knowledge.

* In C++ and Rust, monomorphization is easy. You don't have to do it, but it's easy, so many people do. The containers in the standard library are monomorphized. This code can perform very well in any particular case, but in aggregate it's large enough that I have doubts about whether it's always worth it for the whole program.