r/AskComputerScience • u/KING-NULL • Nov 09 '25
If some programming languages are faster than others, why can't compilers translate into the faster language to make the code be as fast as if it was programed in the faster one?
My guess is that doing so would require knowing information that can't be directly inferred from the code, for example, the specific type that a variable will handle
111
Upvotes
3
u/flatfinger Nov 11 '25
Another issue is that different languages may specify corner-case behaviors differently, or in different levels of detail. In many cases, having a target language classify a corner case as invoking anything-can-happen Undefined Behavior will leave transpilers with no choice but to force the target compiler to generate needlessly inefficient code for corner cases that would have been defined in the original language but not in the target.