2 ms·
Python is absurdly dynamic, but a JIT normally runs a profiler and discovers which paths are actually taken. If an instance attribute is always directly accesse
by nine_k 4y ago
Python is absurdly dynamic, but a JIT normally runs a profiler and discovers which paths are actually taken. If an instance attribute is always directly accessed, and there is no MRO lookup, descriptor / property lookup, getattr lookup, etc, the JIT can optimize it down to the trivial path.
If a non-trivial path is rarely taken, it can be run by interpreting the plain bytecode.
At least it's how I understand things like V8 work.
Smalltalk is also highly dynamic. But it was running so much faster than Java that the Smalltalk's JIT was adopted to speed up Java bytecode. By now Java may rival C speeds with competently written code.