Author: Maciej Fijalkowski <[email protected]>
Branch: extradoc
Changeset: r4832:d390cfda3556
Date: 2012-10-03 09:56 +0200
http://bitbucket.org/pypy/extradoc/changeset/d390cfda3556/
Log: start slides
diff --git a/talk/pyconza2012/examples/alloc.py
b/talk/pyconza2012/examples/alloc.py
new file mode 100644
--- /dev/null
+++ b/talk/pyconza2012/examples/alloc.py
@@ -0,0 +1,20 @@
+
+import sys, time
+
+def f():
+ l = [None]
+ for i in range(int(sys.argv[1])):
+ l[0] = (i,)
+
+def g():
+ m = int(sys.argv[1])
+ l = [None] * m
+ for i in range(m):
+ l[i] = i
+
+t0 = time.time()
+f()
+t1 = time.time()
+g()
+t2 = time.time()
+print "long living", t2 - t1, "short living", t1 - t0
diff --git a/talk/pyconza2012/examples/datastructure.py
b/talk/pyconza2012/examples/datastructure.py
new file mode 100644
--- /dev/null
+++ b/talk/pyconza2012/examples/datastructure.py
@@ -0,0 +1,26 @@
+
+class View(object):
+ def __init__(self, arr, start, stop):
+ self.arr = arr
+ self.start = start
+ self.stop = stop
+
+ def __getitem__(self, item):
+ if not isinstance(item, int):
+ return NotImplemented
+ if self.start + item <= self.stop:
+ raise IndexError
+ return self.arr[self.start + item]
+
+class Wrapper(object):
+ def __init__(self, arr):
+ self.arr = arr
+
+ def __getitem__(self, item):
+ if isinstance(item, int):
+ return self.arr[item]
+ elif isinstance(item, slice):
+ if item.step != 1 or item.start < 0 or item.stop < 0:
+ raise TypeError("step not implemented")
+ return View(self.arr, item.start, item.stop)
+ return NotImplemented
diff --git a/talk/pyconza2012/examples/interpreter.py
b/talk/pyconza2012/examples/interpreter.py
new file mode 100644
--- /dev/null
+++ b/talk/pyconza2012/examples/interpreter.py
@@ -0,0 +1,57 @@
+
+(LOAD_FAST, LOAD_CONST, COMPARE_OP, POP_JUMP_IF_FALSE,
+ ADD, STORE_FAST, JUMP_ABSOLUTE) = range(7)
+
+has_arg = [True, True, False, True, False, True, True]
+
+class BaseObject(object):
+ def add(left, right):
+ # try right
+ return right.radd(left)
+
+class Long(BaseObject):
+ pass
+
+class Integer(BaseObject):
+ def __init__(self, v):
+ self.intval = v
+
+ def add(self, right):
+ if isinstance(right, Integer):
+ try:
+ return Integer(self.intval + right.intval)
+ except OverflowError:
+ return Long(self.intval).add(Long(right.intval))
+
+def interpret(bytecode, variables, constants):
+ stack = []
+ pos = 0
+ arg0 = None
+ while True:
+ b = ord(bytecode[pos])
+ if has_arg[b]:
+ pos += 1
+ arg0 = ord(bytecode[pos])
+ if b == LOAD_FAST:
+ stack.append(variables[arg0])
+ elif b == LOAD_CONST:
+ stack.append(constants[arg0])
+ elif b == COMPARE_OP:
+ right = stack.pop()
+ left = stack.pop()
+ stack.append(left.compare(right))
+ elif b == ADD:
+ right = stack.pop()
+ left = stack.pop()
+ stack.append(left.add(right))
+ elif b == POP_JUMP_IF_FALSE:
+ val = stack.pop()
+ if not val.is_true():
+ pos = arg0
+ continue
+ elif b == STORE_FAST:
+ variables[arg0] = stack.pop()
+ elif b == JUMP_ABSOLUTE:
+ pos = arg0
+ continue
+ pos += 1
diff --git a/talk/pyconza2012/examples/jit01.py
b/talk/pyconza2012/examples/jit01.py
new file mode 100644
--- /dev/null
+++ b/talk/pyconza2012/examples/jit01.py
@@ -0,0 +1,10 @@
+
+def f():
+ i = 0
+ while i < 1000000:
+ i = i + 1
+ return i
+
+if __name__ == '__main__':
+ f()
+
diff --git a/talk/pyconza2012/slides.rst b/talk/pyconza2012/slides.rst
new file mode 100644
--- /dev/null
+++ b/talk/pyconza2012/slides.rst
@@ -0,0 +1,128 @@
+==================================
+Python performance characteristics
+==================================
+
+Who am I?
+---------
+
+* Maciej Fijałkowski (yes this is unicode)
+
+* PyPy core developer for I don't remember
+
+* performance freak
+
+What this talk is about?
+------------------------
+
+* I'll start where Larry finished
+
+* describe a bit how the PyPy JIT works
+
+* what's the difference between interpretation and JIT compilation
+
+|pause|
+
+* who some assembler
+
+|pause|
+
+* just joking
+
+What is PyPy?
+-------------
+
+* PyPy is a Python interpreter (that's what we care about)
+
+* PyPy is a toolchain for creating dynamic language implementations
+
+ * we try to rename the latter RPython
+
+* also, an Open Source project that has been around for a while
+
+Compilers vs interpreters
+-------------------------
+
+* compilers compile language X (C, Python) to a lower level language
+ (C, assembler) ahead of time
+
+* interpreters compile language X to bytecode and have a big interpreter
+ loop
+
+|pause|
+
+* PyPy has a hybrid approach. It's an interpreter, but hot paths are
+ compiled directly to assembler during runtime
+
+What is just in time (JIT) compilation?
+---------------------------------------
+
+* few different flavors
+
+* observe runtime values
+
+* compile code with agressive optimizations
+
+* have checks if assumptions still stand
+
+So what PyPy does?
+------------------
+
+* interprets a Python program
+
+* the JIT observes python **interpreter**
+
+* producing code through the path followed by the interpreter
+
+* compiles loops and functions
+
+Some example
+------------
+
+* integer addition!
+
+So wait, where are those allocations?
+-------------------------------------
+
+* they don't escape, so they're removed!
+
+Abstractions
+------------
+
+* inlining, malloc removal
+
+* abstractions are cheap
+
+|pause|
+
+* if they don't introduce too much complexity
+
+Allocations
+-----------
+
+* allocation is expensive
+
+* for a good GC, short living objects don't matter
+
+* it's better to have a small persistent structure and abstraction
+ on allocation
+
+|pause|
+
+* copying however is expensive
+
+* we have hacks for strings, but they're not complete
+
+Calls
+-----
+
+* Python calls are an incredible mess
+
+* simple is better than complex
+
+* simple call comes with no cost, the cost grows with growing complexity
+
+Attribute access
+----------------
+
+Other sorts of loops
+--------------------
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit