3 ms·
With generics, yes, like C++ templates: each combination of parameters results in one instance. However, you can opt into using trait objects instead, which do
by eddyb 10y ago
With generics, yes, like C++ templates: each combination of parameters results in one instance.
However, you can opt into using trait objects instead, which do use virtual calls.
- ngrilly 10y agoIs pcwalton saying that a JIT compiler is more adequate for a "virtual-heavy" language like Go (to use devirtualization with inline caching and bailout), and an AOT compiler is more adequate for languages like Rust and C++ that mostly use code specialization?
- kibwen 10y agoIt's not quite as clean-cut as that, though it is self-evident that optimizing at runtime (e.g. JIT) is the only recourse for optimizations that are otherwise reliant on runtime information (e.g. dynamic dispatch/virtual calls). Go does have an advantage over Java in that it prefers static semantics (pcwalton's assertion that Go is "virtual heavy" should likely be taken as relative to Rust/C++), so has less to benefit from devirtualization, and thus less of an argument to go the JIT route (which would take monumental engineering effort). I believe pcwalton's points are that 1) running in a virtual machine does not imply that a language is slow (though I bet he'd agree with you that JIT introduces substantial memory overhead), and 2) Java, specifically, is not slow, thanks to a highly-tuned JIT.
- ngrilly 10y agoThanks! That's exactly what I wanted to know.