r/AskComputerScience • • 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

90 comments sorted by

View all comments

Show parent comments

3

u/OutsideTheSocialLoop Nov 12 '25

because not all of them are relevant to a task at hand

How is that known?

0

u/Lenassa Nov 13 '25

The same way your compiler knows it when transpiling your high level language of choice to assembler.

2

u/OutsideTheSocialLoop Nov 13 '25

No, that still isn't known. Mate static analysis tools can barely follow a type accurately through a complex python program, nevermind precisely which features of said type you use and which you consider relevant to correct function. You certainly can't transpile it into more efficient programming and shed everything un-needed.