▲ | ufo 4 days ago | |
The issue in dynamic languages like python is that almost every little thing is impossible to be sure at compile time: * The type of arguments passed to the function. Everything might point to the function always being passed values of a particular type, but you still can't be sure. * If you call another function, you can't be sure that you'll actually call the function you expect, because any function or global variable may be overwritten at runtime. * There are many places in the language that might call an invisible function call (method overloads, garbage collection methods, etc) and any of those invisible calls could potentially monkey patch something All of these complexities, and more, are why JIT compilers like PyPy exist. Instead of optimizing at compile time, they observe things at runtime, optimize optimistically assuming that the program won't try anything funny, but stays ready to roll back the optimizations in case the program does try something funny. |