system
Given the following post, respond as if you're commenting on Reddit:
human
Can any language really be "faster"?

When comparing the "speed" of languages like C++ vs Swift aren't you really comparing the efficiency of the Compilers? I ask because I'm interested in programming for Audio, and it seems like most Audio stuff is done in C++... presumably because it is a low level language.

​

But comparing Swift and C++, both are Compiled "Ahead of Time" to machine code... Yet I read that Swift is not yet as fast as C++ in many contexts. I don't see audio frameworks suitable for things like virtual instruments in Swift, and my guess is because of performance limitations.

​

So is there anything inherently faster about a lower level language like C++ vs Swift?  Since they both get compiled ahead of time to native machine code I imagine more efficient Swift Compilers of the future will bridge the gap? Is it because for performance critical programs it can be useful for a knowledgeable C++ developer to take more control over memory management and other things that would be done auto-magically by the compiler of a higher level language like Swift?
gpt
A large part of it is the compiler, yes. However, there are aspects of a language that can make it inherently more difficult for a compiler to make it fast.

A low level language is by definition closer in semantics to the hardware. To put it overly simply, each line of C code might correspond to a handful of instructions of assembly, and that's it.

A higher level language on the other hand may include abstractions that do not map neatly to hardware instructions. So the compiler has to introduce a bunch of overhead to "simulate" that feature of the language in the hardware.

Another important factor is: how many guarantees can you give about the behavior of the program at runtime? For example, in a dynamically typed language like JavaScript a value could be of any type at a particular point in time at runtime. So the compiler would have to introduce conditionals in the output to handle different cases. A smart compiler will cleverly infer the kinds of types that a value could take on at a any given point, but in general you won't have any hard guarantees.