There is a big difference between JIT compiled _dynamic_ language and ahead of time compiled static language. While modern JS engines show that difference sometimes can be narrowed down with sophisticated JIT and runtime, it is still there.
There is a big difference between JIT compiled _dynamic_ language and ahead of time compiled static language. While modern JS engines show that difference sometimes can be narrowed down with sophisticated JIT and runtime, it is still there.
Ruby's YJIT compiler does compile ahead of time, the details are in the link provided. On the first run it will, if feasible, compile blocks of frequently executed code and stow it away for when it's needed next. So only on the first run is it interpreting everything.
Many interpreted languages have this feature, including PHP these days. But they're still quite slow, because dynamic languages are just slow. Dynamic typing is very suboptimal because generally you have to box A LOT of stuff and burn a lot of memory. That matters because then cache lines get evicted more often, and the performance grinds to a halt.
It used to be in PHP that every array element took 96 bytes (!!!) of booking overhead. That was/is why PHP is slow. That was reduced and performance basically quadrupled for PHP 7.4.
EDIT: sorry just wanted to add I'm being a bit hyperbolic. These languages are fast enough for their use cases, both PHP and Ruby. But compared to even something like C#, this is where the performance gap comes from, despite both being garbage collected.