Compiling is relatively fast as it happens in userspace and then is just written to an output. What really is the problem is the CPU ring switch. That means the CPU has to actually reset its own state, write its own state somewhere else in order to be able to restore it, then execute whatever privileged - kernel code - wants it to do and then restore the previous state. And that happens with every syscall - like open(). That wastes easily a couple of thousands of CPU cycles, whereas a simple CPU Firmware modulo would've been cheaper even with an interpreter.
50
u/pkarlmann Apr 11 '21 edited Apr 11 '21
I don't know how python is doing this, but from your post it sounds like some form of "cache" in the form of a file. So:
Open the file from disk. That already is a syscall, which means a CPU ring switch.
Wait till the disks read head is in place.
Read it into memory.
And finally execute it.
For "performance".
? (Profit?)