3. def interprete():
while True:
age = int(input('age: >> ')) # opcode, kind of
# handlers
if age < 6:
print("Ahh %s, Who is a little cutie?" % age)
elif age < 23:
print(
"So, %s ha? How is your school today?" % age
)
else:
print("Go find a job, you hippie!1")
Is it just me, or...
4. - Frame represents running code
- Code represents instructions and interface for context
PyObject *
PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
{
co = f->f_code;
for (;;) {
switch (opcode) {
TARGET(LOAD_FAST) {* implementation of LOAD_FAST *}
TARGET(LOAD_CONST) {* implementation of LOAD_CONST *}
TARGET(STORE_FAST) {* implementation of STORE_FAST *}
...
}
}
Frame evaluator
5. TARGET(BINARY_ADD) {
PyObject *right = POP();
PyObject *left = TOP();
PyObject *sum;
...
sum = PyNumber_Add(left, right);
...
DISPATCH();
}
C API
20. Example: Say you are asked to sort one
billion numbers, what you gonna do?
The key to performance is specialization
21. ● PyPy: yet another python implementation (fastest on market, though)
● PyPy is written in RPython - turbo ugly subset of python language
● You might think: hmmm, Python, even restricted one - that sounds fun
● It is not, trust me
Before we start: RPython, PyPy etc.
22. ● PyPy: yet another python implementation (fastest on market, though)
● PyPy is written in RPython - turbo ugly subset of python language
● You might think: hmmm, Python, even restricted one - that sounds fun
● It is not, trust me
$ cat demo.py
import os
def main(argv):
os.write(1, 'Is that even legal?n')
return 0
def target(*args):
return main, None
Before we start: RPython, PyPy etc.
26. [Timer] Timings:
[Timer] annotate --- 3.6 s
[Timer] rtype_lltype --- 0.1 s
[Timer] backendopt_lltype --- 0.1 s
[Timer] stackcheckinsertion_lltype --- 0.0 s
[Timer] database_c --- 8.5 s
[Timer] source_c --- 0.9 s
[Timer] compile_c --- 1.8 s
[Timer] =========================================
[Timer] Total: --- 15.0 s
Before we start: RPython, PyPy etc.
27. By Davide Ancona, Carl Friedrich Bolz, Antonio Cuni, and Armin Rigo
Automatic generation of JIT compilers for
dynamic languages in .NET
Я испытал мощный эмоциональный подъем
28. By Yoshihiko Futamura
Having program P, taking inputs s1
...sn
and d1
...dm
S(P, (s1
,..., sm
)) = P’
Produce program P’ such as
P(s1
...sn
, d1
,..., dm
) = P’(d1
,..., dm
)
Partial Evaluation of Computation Process, Revisited
49. ● Apply S function only to hot loops
● Lots of consequent iterations of the loop
take the same path in the CFG
Oook, but the hottest loop in the interpreter is a opcode
dispatch loop.
Assumptions: