Author: Armin Rigo <ar...@tunes.org> Branch: extradoc Changeset: r4085:c6a6febee72c Date: 2012-02-05 11:23 +0100 http://bitbucket.org/pypy/extradoc/changeset/c6a6febee72c/
Log: merge heads diff --git a/talk/pycon2012/tutorial/emails/01_numpy.rst b/talk/pycon2012/tutorial/emails/01_numpy.rst new file mode 100644 --- /dev/null +++ b/talk/pycon2012/tutorial/emails/01_numpy.rst @@ -0,0 +1,17 @@ +PyPy Tutorial - NumPy? +====================== + +Hi, + +We're very excited for our upcoming tutorial at PyCon, and we can't wait to +see you there. As we prepare our material, we're interested in what material +will be most interesting and helpful to you, so we're going to have a lot of +questions for you. Right now we'd like to know, are you interested in hearing +about NumPy for PyPy? As you may know PyPy is working on it's own +implementation of NumPy, with rapidly increasing compatibility, and +performance. However, it does have a pretty different performance profile from +CPython's NumPy. If you're interested in hearing about this in our tutorial, +please let us know. + +Thanks, +Alex Gaynor, Maciej Fijalkoski, Armin Rigo diff --git a/talk/pycon2012/tutorial/examples.rst b/talk/pycon2012/tutorial/examples.rst new file mode 100644 --- /dev/null +++ b/talk/pycon2012/tutorial/examples.rst @@ -0,0 +1,15 @@ + +* Refcount example, where it won't work + +* A simple speedup example and show performance + +* Show memory consumption how it grows for tight instances + +* Some numpy example (?) + +* An example how to use execnet + +* An example how to use matplotlib + +* Large object performance problem (that might go away some time?) + diff --git a/talk/pycon2012/tutorial/examples/01_refcount.py b/talk/pycon2012/tutorial/examples/01_refcount.py new file mode 100644 --- /dev/null +++ b/talk/pycon2012/tutorial/examples/01_refcount.py @@ -0,0 +1,9 @@ + +def wrong(): + open("file").write("data") + assert open("file").read() == "data" + +def right(): + with open("file") as f: + f.write("data") + # contents *will be there* by now diff --git a/talk/pycon2012/tutorial/examples/02_speedup.py b/talk/pycon2012/tutorial/examples/02_speedup.py new file mode 100644 --- /dev/null +++ b/talk/pycon2012/tutorial/examples/02_speedup.py @@ -0,0 +1,11 @@ + +def f(): + s = 0 + for i in xrange(100000000): + s += 1 + return s + +if __name__ == '__main__': + import dis + dis.dis(f) + f() diff --git a/talk/pycon2012/tutorial/examples/03_memory.py b/talk/pycon2012/tutorial/examples/03_memory.py new file mode 100644 --- /dev/null +++ b/talk/pycon2012/tutorial/examples/03_memory.py @@ -0,0 +1,37 @@ + +import time, os, re + +class A(object): + def __init__(self, a, b, c): + self.a = a + self.b = b + self.c = c + +def read_smaps(): + with open("/proc/%d/smaps" % os.getpid()) as f: + mark = False + for line in f: + if mark: + assert line.startswith('Size:') + m = re.search('(\d+).*', line) + return m.group(0), int(m.group(1)) + if 'heap' in line: + mark = True + +def main(): + l = [] + count = 0 + for k in range(100): + t0 = time.time() + for i in range(100000): + l.append(A(1, 2, i)) + for j in range(4): + A(1, 1, 2) + count += i + print time.time() - t0 + usage, kb = read_smaps() + print usage, kb * 1024 / count, "per instance" + time.sleep(1) + +if __name__ == '__main__': + main() diff --git a/talk/pycon2012/tutorial/outline.rst b/talk/pycon2012/tutorial/outline.rst new file mode 100644 --- /dev/null +++ b/talk/pycon2012/tutorial/outline.rst @@ -0,0 +1,31 @@ +How to get the most out of PyPy +=============================== + +* Why would you use PyPy - a quick look: + * performance + * memory consumption + * numpy (soon) + * sandbox +* Why you would not use PyPy (yet) + * embedded + * some extensions don't work (lxml) + * but there are ways around it! +* How PyPy Works + * Bytecode VM + * GC + * not refcounting + * Generational + * Implications (building large objects) + * JIT + * JIT + Python + * mapdict + * globals/builtins + * tracing + * resops + * optimizations +* A case study + * Examples, examples, examples + * Open source application (TBD) + * Jitviewer +* Putting it to work + * Workshop style diff --git a/talk/pycon2012/tutorial/slides.rst b/talk/pycon2012/tutorial/slides.rst new file mode 100644 --- /dev/null +++ b/talk/pycon2012/tutorial/slides.rst @@ -0,0 +1,122 @@ +Why PyPy? +========= + +* performance + +* memory + +* sandbox + +Why not PyPy (yet)? +=================== + +* embedded python interpreter + +* embedded systems + +* not x86-based systems + +* extensions, extensions, extensions + +Performance +=========== + +* the main thing we'll concentrate on today + +* PyPy is an interpreter + a JIT + +* compiling Python to assembler via magic (we'll talk about it later) + +* very different performance characteristics from CPython + +Performance sweetspots +====================== + +* every VM has it's sweetspot + +* we try hard to make it wider and wider + +CPython's sweetspot +=================== + +* moving computations to C, example:: + + map(operator.... ) # XXX some obscure example + +PyPy's sweetpot +=============== + +* **simple** python + +* if you can't understand it, JIT won't either + +How PyPy runs your program, involved parts +========================================== + +* a simple bytecode compiler (just like CPython) + +* an interpreter loop written in RPython + +* a JIT written in RPython + +* an assembler backend + +Bytecode interpreter +==================== + +* executing one bytecode at a time + +* add opcode for example + +* .... goes on and on + +* XXX example 1 + +Tracing JIT +=========== + +* once the loop gets hot, it's starting tracing (1039 runs, or 1619 function + calls) + +* generating operations following how the interpreter would execute them + +* optimizing them + +* compiling to assembler (x86 only for now) + +PyPy's specific features +======================== + +* JIT complete by design, as long as the interpreter is correct + +* Only **one** language description, in a high level language + +* Decent tools for inspecting the generated code + +XXXXXXXXXXXXXXXXXXXXXXXXXXXX + + +* Sweetspot? + + * CPython's sweetspot: stuff written in C + + * PyPy's sweetspot: lots of stuff written in Python + +* http://speed.pypy.org + +* How do you hit the sweetspot? + + * Be in this room for the next 3 hours. + +Memory +====== + +* PyPy memory usage is difficult to estimate. +* Very program dependent. +* Learn to predict! + +Sandbox +======= + +* We're not going to talk about it here. +* Run untrusted code. _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit