[pypy-svn] r69041 - in pypy/extradoc/talk/rupy2009: . examples
fijal at codespeak.net
fijal at codespeak.net
Fri Nov 6 22:14:33 CET 2009
Author: fijal
Date: Fri Nov 6 22:14:30 2009
New Revision: 69041
Added:
pypy/extradoc/talk/rupy2009/examples/escaping.py (contents, props changed)
pypy/extradoc/talk/rupy2009/examples/instance.py (contents, props changed)
pypy/extradoc/talk/rupy2009/examples/interp.py (contents, props changed)
pypy/extradoc/talk/rupy2009/examples/loop.py (contents, props changed)
pypy/extradoc/talk/rupy2009/time.png (contents, props changed)
Modified:
pypy/extradoc/talk/rupy2009/talk.pdf
pypy/extradoc/talk/rupy2009/talk.tex
Log:
update + some examples
Added: pypy/extradoc/talk/rupy2009/examples/escaping.py
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/rupy2009/examples/escaping.py Fri Nov 6 22:14:30 2009
@@ -0,0 +1,12 @@
+
+[x, y, z]
+v0 = IntObject(x.value % y.value)
+return IntObject(z.value + v0.value)
+
+
+
+
+
+[x, y, z]
+i0 = x.value % y.value
+return IntObject(z.value + i0)
Added: pypy/extradoc/talk/rupy2009/examples/instance.py
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/rupy2009/examples/instance.py Fri Nov 6 22:14:30 2009
@@ -0,0 +1,15 @@
+
+class A(object):
+ def __init__(self, next, v):
+ self.next = next
+ self.v = v
+
+def f():
+ a = A(None, 0)
+ i = 0
+ while i < 1000000:
+ a = A(a, i)
+ i += 1
+ return a
+
+f()
Added: pypy/extradoc/talk/rupy2009/examples/interp.py
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/rupy2009/examples/interp.py Fri Nov 6 22:14:30 2009
@@ -0,0 +1,30 @@
+
+
+[x, y]
+# LOAD_FAST
+frame.valuestack.push(frame.locals[0])
+# LOAD_FAST
+frame.valuestack.push(frame.locals[1])
+# BINARY_ADD
+v1 = frame.valuestack.pop()
+v0 = frame.valuestack.pop()
+v2 = v0.add(v1)
+ return IntObject(self.value + other.value)
+frame.valustack.push(v2)
+# RETURN_VALUE
+return frame.valuestack[-1]
+
+
+
+[x, y]
+v0 = IntObject(x.value + y.value)
+return v0
+
+
+
+
+[x, y]
+return x + y
+
+
+
Added: pypy/extradoc/talk/rupy2009/examples/loop.py
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/rupy2009/examples/loop.py Fri Nov 6 22:14:30 2009
@@ -0,0 +1,8 @@
+def f():
+ i = 0
+ s = 0
+ while i < 1000000:
+ s += (i % 10)
+ i += 1
+
+f()
Modified: pypy/extradoc/talk/rupy2009/talk.pdf
==============================================================================
Files pypy/extradoc/talk/rupy2009/talk.pdf (original) and pypy/extradoc/talk/rupy2009/talk.pdf Fri Nov 6 22:14:30 2009 differ
Modified: pypy/extradoc/talk/rupy2009/talk.tex
==============================================================================
--- pypy/extradoc/talk/rupy2009/talk.tex (original)
+++ pypy/extradoc/talk/rupy2009/talk.tex Fri Nov 6 22:14:30 2009
@@ -13,6 +13,7 @@
\usepackage{times}
\usepackage[T1]{fontenc}
+\usepackage{color}
\title{The speed of PyPy}
@@ -55,7 +56,7 @@
\begin{itemize}
\item Is Python really slow?
\pause
- \item Sometimes
+ \item Sometimes, for some usecases
\pause
\item Let's have a look at some examples
\end{itemize}
@@ -81,7 +82,7 @@
\vspace{.5cm}
\begin{tabular}{| l | c | r |}
\hline
- & CPython & JVM (client mode) \\
+ & CPython & Java (hotspot client mode) \\
Average of 10 runs: & 7.6s & 0.77s \\
\hline
\end{tabular}
@@ -125,17 +126,291 @@
\end{frame}
\begin{frame}
+ \frametitle{Some evidence}
+ \begin{figure}
+ \includegraphics[width=1.0\textwidth]{time.png}
+ \end{figure}
+\end{frame}
+
+\begin{frame}
\frametitle{Why is Python hard to optimize?}
\begin{itemize}
\item Duck typing (dynamic dispatch)
\item Frames
\item Object encapsulation
\item Dictionaries of instances
+ \item Changing globals
\item Ability to dynamically change builtins
\end{itemize}
\end{frame}
\begin{frame}
+ \frametitle{Duck typing}
+ \begin{itemize}
+ \item Dispatching over item type
+ \item {\tt z = x + y}
+ \item Needs to check what the type of {\tt x} and {\tt y} is
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Frames}
+ \begin{itemize}
+ \item Python interpreters use frames on heap (instead of stack)
+ \item Locals are stored on those frames
+ \item Intermediate results are store on valuestack of frames
+ \item In fact, you can access frames via {\tt sys.\_getframe() or
+ traceback}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Object encapsulation}
+ \begin{itemize}
+ \item Also called boxing
+ \item Each object, even {\tt int}, has to be boxed
+ \item Requires allocations and indirection
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Example - addition}
+ \begin{itemize}
+ \item {\tt z = x + y}
+ \item read value for {\tt x} from frame, store on valuestack
+ \item read value for {\tt x} from frame, store on valuestack
+ \item allocate new integer
+ \item read two values from valuestack, add and store the result in
+ freshly allocated integer
+ \item move the result from valuestack to locals
+ \pause
+ \item {\color{red} in fact, should be one assembler instruction}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Dictionaries of instances}
+ \begin{itemize}
+ \item Need to perform a dictionary lookup for {\tt x.y}
+ \item There are {\bf three} lookups per method call
+ (descriptor, object, type)
+ \item {\bf Two} for attribute access
+ (descriptor, object)
+ \item Looks like list lookup should be enough
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Changing globals}
+ \begin{itemize}
+ \item Global symbols can change at any moment in time
+ \item Makes for example inlining hard
+ \item Requires global dict lookups, even for constants
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Ability to dynamically change builtins}
+ \begin{itemize}
+ \item You can say {\tt int = my\_function}
+ \item But you can't {\tt int.\_\_add\_\_ = my\_method}
+ \item Still messes up optimizations
+ \item Global lookup is also a dictionary lookup, even if globals
+ don't change
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Interpreting vs compiling}
+ \begin{itemize}
+ \item Apparently, processors are good at branch prediction
+ \item We didn't measure much of a difference, less than 2x overall
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{CPython specific problems}
+ \begin{itemize}
+ \item In general, CPython is fairly well optimized
+ \item refcounting is an inefficient garbage collection scheme
+ \item GIL
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Dynamic compilation to the rescue}
+ \begin{itemize}
+ \item You don't pay for feature, until you actually use it
+ \item In static compilation, compiler has to prove that bad
+ things can't happen
+ \item Impossible in Python
+ \item With dynamic compilation, you just throw away compiled
+ code in case things go wrong or start over
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Dealing with frames}
+ \begin{itemize}
+ \item Allocate frame
+ \pause
+ \item Use C stack, but remember where frame fields are
+ living on the stack
+ \pause
+ \item Be able to reconstruct frame on demand (for example
+ {\tt sys.\_getframe() was called})
+ \pause
+ \item The effect is that you don't pay for frames, unless
+ you really use them
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Dealing with dynamic dispatch}
+ \begin{itemize}
+ \item The answer is to simply specialize over types
+ \item Provides possibly multiple versions of compiled code for
+ single Python code
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Dealing with object encapsulation}
+ \begin{itemize}
+ \item ``Virtual objects''
+ \item Also known as escape analysis
+ \item If object does not ``escape'', don't allocate it at all
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{How does it work in practice?}
+ \begin{itemize}
+ \pause
+ \item Pretty well
+ \pause
+ \item XXXX speedup over CPython
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Dealing with attribute access}
+ \begin{itemize}
+ \item Fairly complex task
+ \item Sharing dict, more or less the same effect as V8's hidden
+ classes
+ \pause
+ \item Python is a very complex language
+ \item Shadowing methods with attributes
+ \item Descriptors before attributes
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Other important optimizations}
+ \begin{itemize}
+ \item Caching globals
+ \item Caching builtins
+ \item A lot of smaller ones
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{CPython vs PyPy}
+ \begin{itemize}
+ \item I use CPython for everyday usage
+ \pause
+ \item But personally, I hope to change it in next months
+ \pause
+ \item ... in places where performance matters, but that don't
+ depend on third party C modules (like numpy)
+ \pause
+ \item ... like building and developing PyPy
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Status of PyPy}
+ \begin{itemize}
+ \item Very compliant Python interpreter
+ \item Most of important stdlib modules
+ \item Differencies are agreed to be implementation details
+ \pause
+ \item {\color{red} or bugs}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Examples of working programs}
+ \begin{itemize}
+ \item Django (sqlite only)
+ \item Twisted
+ \item PyPy's translation toolchain
+ \item ctypes
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Status of JIT}
+ \begin{itemize}
+ \item Because the way it's constructed, handles all Python language
+ features (unlike for example {\bf Psyco})
+ \item Changes very quickly these days
+ \item Ready for cautious tests
+ \item Not ready as a drop-in replacement of CPython
+ \pause
+ \item {\color{green} yet!}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Adapt today!}
+ \begin{itemize}
+ \item A fact: People rely on deep obscure features of language
+ \item Examples:
+ \pause
+ \begin{itemize}
+ \item {\tt except ImportError, e: \\ \quad if str(e) != ...:
+ raise}
+ \pause
+ \item Exact naming of list comprehension variable
+ \pause
+ \item Immediate finalization
+ \end{itemize}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Profit tomorrow!}
+ \begin{itemize}
+ \item We plan to release JIT-ready version somewhere early 2010
+ xxx
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{How you can help}
+ \begin{itemize}
+ \item It's all open source after all ...
+ \item Try running existing programs
+ \item Profile, report bugs
+ \pause
+ \item Talk to your boss (XXX)
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Thank you!}
+ \begin{itemize}
+ \item This talk is already online (with all examples):
+ {\tt http://codespeak.net/svn/pypy/dist/extradoc/talk/rupy2009/talk.pdf}
+ \item {\tt http://morepypy.blogspot.com}
+ \item \#pypy on freenode
+ \item If you want to know more about PyPy, feel free to bug me
+ around (like, how does the JIT work?)
+ \item Any questions?
+ \end{itemize}
\end{frame}
\end{document}
+
Added: pypy/extradoc/talk/rupy2009/time.png
==============================================================================
Binary file. No diff available.
More information about the Pypy-commit
mailing list