SlideShare une entreprise Scribd logo
1  sur  47
Télécharger pour lire hors ligne
PyPy 1.2: snakes never crawled so fast
                                           Antonio Cuni
                                            Armin Rigo

                                           Pycon Italia Qu4ttro


                                           May 8 2010




antocuni, arigato (Pycon Italia Qu4ttro)         PyPy 1.2         May 8 2010   1 / 35
Outline


             PyPy 1.2: what’s new and status update

             Overview of the JIT

             Demo: how to use PyPy right now




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   1 / 35
Part 0: What is PyPy? :-)

             Python interpreter written in Python

             Framework for developing dynamic languages

             etc. etc.


             From the user point of view

             An alternative to CPython

             with more features!




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   2 / 35
Part 0: What is PyPy? :-)

             Python interpreter written in Python

             Framework for developing dynamic languages

             etc. etc.


             From the user point of view

             An alternative to CPython

             with more features!




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   2 / 35
Part 1


             What’s new and status update




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   3 / 35
What’s new in PyPy 1.2

             Released on March 12th, 2010

             Main theme: speed

             JIT compiler

             speed.pypy.org

             Ubuntu packages




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   4 / 35
Speed: PyPy vs CPython




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   5 / 35
Speed: PyPy vs Psyco




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   6 / 35
Speed: Demo

             Django application
             Mandelbrot fractal
                       fished randomly on the net :-)

             Run both on CPython and PyPy
                       django trunk!




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2     May 8 2010   7 / 35
What works on PyPy
             Pure Python modules should Just Work (TM)
                       django trunk
                       twisted, nevow
                       pylons
                       bittorrent
                       ...


             lot of standard modules

                       __builtin__ __pypy__ _codecs _lsprof _minimal_curses
                       _random _rawffi _socket _sre _weakref bz2 cStringIO crypt errno
                       exceptions fcntl gc itertools marshal math md5 mmap operator parser
                       posix pyexpat select sha signal struct symbol sys termios thread time
                       token unicodedata zipimport zlib
                       array binascii cPickle cmath collections ctypes datetime functools grp
                       md5 pwd pyexpat sha sqlite3 syslog
                       ctypes
antocuni, arigato (Pycon Italia Qu4ttro)          PyPy 1.2                          May 8 2010   8 / 35
What works on PyPy
             Pure Python modules should Just Work (TM)
                       django trunk
                       twisted, nevow
                       pylons
                       bittorrent
                       ...


             lot of standard modules

                       __builtin__ __pypy__ _codecs _lsprof _minimal_curses
                       _random _rawffi _socket _sre _weakref bz2 cStringIO crypt errno
                       exceptions fcntl gc itertools marshal math md5 mmap operator parser
                       posix pyexpat select sha signal struct symbol sys termios thread time
                       token unicodedata zipimport zlib
                       array binascii cPickle cmath collections ctypes datetime functools grp
                       md5 pwd pyexpat sha sqlite3 syslog
                       ctypes
antocuni, arigato (Pycon Italia Qu4ttro)          PyPy 1.2                          May 8 2010   8 / 35
What does not work on PyPy
             Pure Python modules should Just Work (TM)
                       ... unless they don’t :-)


             Programs that rely on CPython-specific behavior
                       refcounting:        open(’xxx’, ’w’).write(’stuff’)
                       non-string keys in dict of types (try it!)
                       exact naming of a list comprehension variable
                       exact message matching in exception catching code
                       ...


             Extension modules
                       really?
                       drum roll...



antocuni, arigato (Pycon Italia Qu4ttro)        PyPy 1.2            May 8 2010   9 / 35
What does not work on PyPy
             Pure Python modules should Just Work (TM)
                       ... unless they don’t :-)


             Programs that rely on CPython-specific behavior
                       refcounting:        open(’xxx’, ’w’).write(’stuff’)
                       non-string keys in dict of types (try it!)
                       exact naming of a list comprehension variable
                       exact message matching in exception catching code
                       ...


             Extension modules
                       really?
                       drum roll...



antocuni, arigato (Pycon Italia Qu4ttro)        PyPy 1.2            May 8 2010   9 / 35
What does not work on PyPy
             Pure Python modules should Just Work (TM)
                       ... unless they don’t :-)


             Programs that rely on CPython-specific behavior
                       refcounting:        open(’xxx’, ’w’).write(’stuff’)
                       non-string keys in dict of types (try it!)
                       exact naming of a list comprehension variable
                       exact message matching in exception catching code
                       ...


             Extension modules
                       really?
                       drum roll...



antocuni, arigato (Pycon Italia Qu4ttro)        PyPy 1.2            May 8 2010   9 / 35
What does not work on PyPy
             Pure Python modules should Just Work (TM)
                       ... unless they don’t :-)


             Programs that rely on CPython-specific behavior
                       refcounting:        open(’xxx’, ’w’).write(’stuff’)
                       non-string keys in dict of types (try it!)
                       exact naming of a list comprehension variable
                       exact message matching in exception catching code
                       ...


             Extension modules
                       really?
                       drum roll...



antocuni, arigato (Pycon Italia Qu4ttro)        PyPy 1.2            May 8 2010   9 / 35
What does not work on PyPy
             Pure Python modules should Just Work (TM)
                       ... unless they don’t :-)


             Programs that rely on CPython-specific behavior
                       refcounting:        open(’xxx’, ’w’).write(’stuff’)
                       non-string keys in dict of types (try it!)
                       exact naming of a list comprehension variable
                       exact message matching in exception catching code
                       ...


             Extension modules
                       really?
                       drum roll...



antocuni, arigato (Pycon Italia Qu4ttro)        PyPy 1.2            May 8 2010   9 / 35
cpyext
             CPython extension modules in PyPy

             pypy-c setup.py build
             still beta

             not 100% of CPython API is supported

             not included in PyPy 1.2
             Known to work:
                       wxPython (after a patch)
                       _sre
                       PyCrypto
                       PIL




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   10 / 35
wxPython on PyPy (1)




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   11 / 35
wxPython on PyPy (2)




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   12 / 35
PyPy 1.2.1

             Coming soon
             Many bugfixes
                       27 issues reported after release of 1.2

             beta version of cpyext




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2              May 8 2010   13 / 35
Part 2: Just-in-Time compilation


             Snakes never crawled so fast




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   14 / 35
Overview of implementations

             CPython

             Stackless

             Psyco

             Jython

             IronPython

             PyPy (without and with JIT)

             Unladen Swallow




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   15 / 35
Demo




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   16 / 35
Features

             it just works

             it may give good speed-ups (better than Psyco)

             it may have a few bugs left (Psyco too)

             it is not a hack (unlike Psyco)

             PyPy also has excellent memory usage
                       half that of CPython for a program using several
                       hunderds MBs




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2               May 8 2010   17 / 35
Features

             it just works

             it may give good speed-ups (better than Psyco)

             it may have a few bugs left (Psyco too)

             it is not a hack (unlike Psyco)

             PyPy also has excellent memory usage
                       half that of CPython for a program using several
                       hunderds MBs




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2               May 8 2010   17 / 35
Features

             it just works

             it may give good speed-ups (better than Psyco)

             it may have a few bugs left (Psyco too)

             it is not a hack (unlike Psyco)

             PyPy also has excellent memory usage
                       half that of CPython for a program using several
                       hunderds MBs




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2               May 8 2010   17 / 35
What is a JIT

             CPython compiles the program source into bytecodes

             without a JIT, the bytecodes are then interpreted

             with a JIT, the bytecodes are further translated to
             machine code (assembler)




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2    May 8 2010   18 / 35
What is a JIT (2)
    The translation can be:
             syntactic: translate the whole functions into machine
             code
                       “the obvious way”
                       e.g. Pyrex/Cython, Unladen Swallow
                       not good performance, or needs tricks

             semantic: translate bits of the function just-in-time
                       only used parts
                       exploit runtime information (e.g. types)
                       Psyco, PyPy




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2               May 8 2010   19 / 35
What is a JIT (2)
    The translation can be:
             syntactic: translate the whole functions into machine
             code
                       “the obvious way”
                       e.g. Pyrex/Cython, Unladen Swallow
                       not good performance, or needs tricks

             semantic: translate bits of the function just-in-time
                       only used parts
                       exploit runtime information (e.g. types)
                       Psyco, PyPy




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2               May 8 2010   19 / 35
What is a tracing JIT

             start by interpreting normally

             find loops as they are executed

             turn them into machine code

             80% of the time is spent in 20% of the code




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   20 / 35
What is a tracing JIT (history)

             tracing assembler (Dynamo, ~2000)

             tracing Java (~2005)

             tracing JavaScript (~2008)


             PyPy is a “tracing JIT generator”




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   21 / 35
What is a tracing JIT (history)

             tracing assembler (Dynamo, ~2000)

             tracing Java (~2005)

             tracing JavaScript (~2008)


             PyPy is a “tracing JIT generator”




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   21 / 35
The architecture of PyPy




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   22 / 35
Speed of the PyPy JIT

    Python programs that are, or are not, nicely handled by
    the JIT:

             loops, even across many calls, are nicely handled
             loops with very many taken paths are not
                       e.g. Python programs that look like interpreters
                       typical in tracing JITs

             bad support so far for generators and recursion




antocuni, arigato (Pycon Italia Qu4ttro)    PyPy 1.2               May 8 2010   23 / 35
The optimizations we get

             !=     optimizations we wrote :-)
             removed frame handling
                       local variables are in CPU registers or on the C stack
                       but   sys._getframe()    works correctly

             “virtuals”: temporary objects are not constructed
                       e = a + b + c + d
                       and much more complex examples

             attribute and method lookups, etc.




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2                May 8 2010   24 / 35
Example
      def g(a, b):                                ADD EAX, 1
      if a < 5: # 2                               CMP EAX, EBX
      return -1                                   JNL <guard 1>
      return a - b # 3                            CMP EAX, 0
                                                  JL <guard 2>
      def f(x):                                   MOV ECX, EAX
      total = 0                                   SUB ECX, EBX
      # 1                                         JO <guard 3>
      for i in range(x):                          ADD EDX, ECX
      d = g(i, x)                                 JO <guard 4>
      total += d # 4                              JMP

antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2           May 8 2010   25 / 35
Example
      def g(a, b):                                ADD EAX, 1
      if a < 5: # 2                               CMP EAX, EBX
      return -1                                   JNL <guard 1>
      return a - b # 3                            CMP EAX, 0
                                                  JL <guard 2>
      def f(x):                                   MOV ECX, EAX
      total = 0                                   SUB ECX, EBX
      # 1                                         JO <guard 3>
      for i in range(x):                          ADD EDX, ECX
      d = g(i, x)                                 JO <guard 4>
      total += d # 4                              JMP

antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2           May 8 2010   25 / 35
Practical results

             fast :-)

             so far, x86-32 only

             relatively easy to maintain (or port to x86-64, etc.)
             reminder: works transparently for any Python code
                       or any language (Prolog JIT :-) at PPDP 2010)

             viable alternative to CPython




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2             May 8 2010   26 / 35
Part 3


    How to use PyPy right now




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   27 / 35
Mandelbrot demo

             Works purely on PyPy
             Not always the case
                       missing extension modules (cpyext mitigates the
                       problem)
                       libraries that rely on CPython details
                       ...

             clear performance-critical part




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2              May 8 2010   28 / 35
CPython and PyPy side by side

             CPython: runs the main application

             PyPy: subprocess, runs only the hotspots

             How do they communicate?
             execnet
                       The Ring of Python, Holger Krekel, 9:00
                       oups, too late :-)




antocuni, arigato (Pycon Italia Qu4ttro)    PyPy 1.2             May 8 2010   29 / 35
Rendering (1)
    Mandelbrot
    def render(request):
    w = int(request.GET.get(’w’, 320))
    h = int(request.GET.get(’h’, 240))

    from py_mandel import mandelbrot
    img = mandelbrot(w, h)

    return HttpResponse(img, content_type="image/bmp")




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   30 / 35
Rendering (2)
    Mandelbrot on PyPy
    def pypy_render(request):
    w = int(request.GET.get(’w’, 320))
    h = int(request.GET.get(’h’, 240))

    channel = pypy.remote_exec("""
    from py_mandel import mandelbrot
    w, h = channel.receive()
    img = mandelbrot(w, h)
    channel.send(img)
    """)
    channel.send((w, h))
    img = channel.receive()

    return HttpResponse(img, content_type="image/bmp")
antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   31 / 35
execnet setup
    At startup
    import execnet
    mygroup = execnet.Group()
    pypy = mygroup.makegateway("popen//python=pypy-c")
    pypy.remote_exec("""
    import sys
    import os
    os.chdir("mandelbrot")
    sys.path.insert(0, ’’)
    """)



antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   32 / 35
Demo




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2   May 8 2010   33 / 35
Benchmarks
                             1400




                             1200




                             1000
        response time (ms)




                              800


                                                                                   pypy
                                                                                   pypy+pypy
                              600                                                  cpython
                                                                                   cpython+pypy



                              400




                              200




                               0
                                    0   2   4         6      8   10          12

                                                requests/s




antocuni, arigato (Pycon Italia Qu4ttro)         PyPy 1.2             May 8 2010       34 / 35
Contact / Q&A

             Antonio Cuni: at http://merlinux.eu

             Armin Rigo: arigo (at) tunes.org
             Links:
                       PyPy: http://pypy.org/
                       PyPy speed center: http://speed.pypy.org/
                       Blog: http://morepypy.blogspot.com




antocuni, arigato (Pycon Italia Qu4ttro)   PyPy 1.2                May 8 2010   35 / 35

Contenu connexe

Tendances

Python course syllabus
Python course syllabusPython course syllabus
Python course syllabusSugantha T
 
Python, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for EngineersPython, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for EngineersBoey Pak Cheong
 
Communication between Java and Python
Communication between Java and PythonCommunication between Java and Python
Communication between Java and PythonAndreas Schreiber
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming pptismailmrribi
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners Sujith Kumar
 
Python 3.5: An agile, general-purpose development language.
Python 3.5: An agile, general-purpose development language.Python 3.5: An agile, general-purpose development language.
Python 3.5: An agile, general-purpose development language.Carlos Miguel Ferreira
 
Introduction about Python by JanBask Training
Introduction about Python by JanBask TrainingIntroduction about Python by JanBask Training
Introduction about Python by JanBask TrainingJanBask Training
 
Benefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonBenefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonparadisetechsoftsolutions
 
Python Introduction | JNTUA | R19 | UNIT 1
Python Introduction | JNTUA | R19 | UNIT 1 Python Introduction | JNTUA | R19 | UNIT 1
Python Introduction | JNTUA | R19 | UNIT 1 FabMinds
 
How to integrate python into a scala stack
How to integrate python into a scala stackHow to integrate python into a scala stack
How to integrate python into a scala stackFliptop
 
11 Unit1 Chapter 1 Getting Started With Python
11   Unit1 Chapter 1 Getting Started With Python11   Unit1 Chapter 1 Getting Started With Python
11 Unit1 Chapter 1 Getting Started With PythonPraveen M Jigajinni
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyTIB Academy
 
What do you mean it needs to be Java based? How jython saved the day.
What do you mean it needs to be Java based? How jython saved the day.What do you mean it needs to be Java based? How jython saved the day.
What do you mean it needs to be Java based? How jython saved the day.Mark Rees
 

Tendances (20)

Basics of python
Basics of pythonBasics of python
Basics of python
 
Python course syllabus
Python course syllabusPython course syllabus
Python course syllabus
 
Mixing Python and Java
Mixing Python and JavaMixing Python and Java
Mixing Python and Java
 
Python, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for EngineersPython, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for Engineers
 
Communication between Java and Python
Communication between Java and PythonCommunication between Java and Python
Communication between Java and Python
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming ppt
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners
 
Python 3.5: An agile, general-purpose development language.
Python 3.5: An agile, general-purpose development language.Python 3.5: An agile, general-purpose development language.
Python 3.5: An agile, general-purpose development language.
 
Python
PythonPython
Python
 
Introduction about Python by JanBask Training
Introduction about Python by JanBask TrainingIntroduction about Python by JanBask Training
Introduction about Python by JanBask Training
 
Benefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonBenefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of python
 
Python Introduction | JNTUA | R19 | UNIT 1
Python Introduction | JNTUA | R19 | UNIT 1 Python Introduction | JNTUA | R19 | UNIT 1
Python Introduction | JNTUA | R19 | UNIT 1
 
How to integrate python into a scala stack
How to integrate python into a scala stackHow to integrate python into a scala stack
How to integrate python into a scala stack
 
11 Unit1 Chapter 1 Getting Started With Python
11   Unit1 Chapter 1 Getting Started With Python11   Unit1 Chapter 1 Getting Started With Python
11 Unit1 Chapter 1 Getting Started With Python
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academy
 
What do you mean it needs to be Java based? How jython saved the day.
What do you mean it needs to be Java based? How jython saved the day.What do you mean it needs to be Java based? How jython saved the day.
What do you mean it needs to be Java based? How jython saved the day.
 
Introduction to Python Basics Programming
Introduction to Python Basics ProgrammingIntroduction to Python Basics Programming
Introduction to Python Basics Programming
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Python final ppt
Python final pptPython final ppt
Python final ppt
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 

Similaire à PyPy 1.2: snakes never crawled so fast

PyPy's approach to construct domain-specific language runtime
PyPy's approach to construct domain-specific language runtimePyPy's approach to construct domain-specific language runtime
PyPy's approach to construct domain-specific language runtimeNational Cheng Kung University
 
Python intro
Python introPython intro
Python introrik0
 
Moving to Python 3
Moving to Python 3Moving to Python 3
Moving to Python 3Nick Efford
 
Python Evolution
Python EvolutionPython Evolution
Python EvolutionQuintagroup
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxusvirat1805
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsHenry Schreiner
 
Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experiencedzynofustechnology
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksEueung Mulyana
 
Magical float repr
Magical float reprMagical float repr
Magical float reprdickinsm
 
CrashCourse: Python with DataCamp and Jupyter for Beginners
CrashCourse: Python with DataCamp and Jupyter for BeginnersCrashCourse: Python with DataCamp and Jupyter for Beginners
CrashCourse: Python with DataCamp and Jupyter for BeginnersOlga Scrivner
 
SunPy: Python for solar physics
SunPy: Python for solar physicsSunPy: Python for solar physics
SunPy: Python for solar physicssegfaulthunter
 
Programming with Python - Basic
Programming with Python - BasicProgramming with Python - Basic
Programming with Python - BasicMosky Liu
 
2010 08-19-30 minutes of python
2010 08-19-30 minutes of python2010 08-19-30 minutes of python
2010 08-19-30 minutes of pythonKang-Min Wang
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientistsaeberspaecher
 

Similaire à PyPy 1.2: snakes never crawled so fast (20)

Chapter - 1.pptx
Chapter - 1.pptxChapter - 1.pptx
Chapter - 1.pptx
 
PyPy's approach to construct domain-specific language runtime
PyPy's approach to construct domain-specific language runtimePyPy's approach to construct domain-specific language runtime
PyPy's approach to construct domain-specific language runtime
 
Python intro
Python introPython intro
Python intro
 
Moving to Python 3
Moving to Python 3Moving to Python 3
Moving to Python 3
 
Python Evolution
Python EvolutionPython Evolution
Python Evolution
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python Extensions
 
Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experienced
 
Introduction to python3.pdf
Introduction to python3.pdfIntroduction to python3.pdf
Introduction to python3.pdf
 
Elasticwulf Pycon Talk
Elasticwulf Pycon TalkElasticwulf Pycon Talk
Elasticwulf Pycon Talk
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
 
Magical float repr
Magical float reprMagical float repr
Magical float repr
 
CrashCourse: Python with DataCamp and Jupyter for Beginners
CrashCourse: Python with DataCamp and Jupyter for BeginnersCrashCourse: Python with DataCamp and Jupyter for Beginners
CrashCourse: Python with DataCamp and Jupyter for Beginners
 
SunPy: Python for solar physics
SunPy: Python for solar physicsSunPy: Python for solar physics
SunPy: Python for solar physics
 
C pythontalk
C pythontalkC pythontalk
C pythontalk
 
Python unit1
Python unit1Python unit1
Python unit1
 
Programming with Python - Basic
Programming with Python - BasicProgramming with Python - Basic
Programming with Python - Basic
 
2010 08-19-30 minutes of python
2010 08-19-30 minutes of python2010 08-19-30 minutes of python
2010 08-19-30 minutes of python
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientists
 
Pl/Python
Pl/PythonPl/Python
Pl/Python
 

Plus de PyCon Italia

Feed back report 2010
Feed back report 2010Feed back report 2010
Feed back report 2010PyCon Italia
 
Spyppolare o non spyppolare
Spyppolare o non spyppolareSpyppolare o non spyppolare
Spyppolare o non spyppolarePyCon Italia
 
zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"
zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"
zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"PyCon Italia
 
Undici anni di lavoro con Python
Undici anni di lavoro con PythonUndici anni di lavoro con Python
Undici anni di lavoro con PythonPyCon Italia
 
socket e SocketServer: il framework per i server Internet in Python
socket e SocketServer: il framework per i server Internet in Pythonsocket e SocketServer: il framework per i server Internet in Python
socket e SocketServer: il framework per i server Internet in PythonPyCon Italia
 
Qt mobile PySide bindings
Qt mobile PySide bindingsQt mobile PySide bindings
Qt mobile PySide bindingsPyCon Italia
 
Python: ottimizzazione numerica algoritmi genetici
Python: ottimizzazione numerica algoritmi geneticiPython: ottimizzazione numerica algoritmi genetici
Python: ottimizzazione numerica algoritmi geneticiPyCon Italia
 
Python in the browser
Python in the browserPython in the browser
Python in the browserPyCon Italia
 
PyCuda: Come sfruttare la potenza delle schede video nelle applicazioni python
PyCuda: Come sfruttare la potenza delle schede video nelle applicazioni pythonPyCuda: Come sfruttare la potenza delle schede video nelle applicazioni python
PyCuda: Come sfruttare la potenza delle schede video nelle applicazioni pythonPyCon Italia
 
OpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonOpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonPyCon Italia
 
New and improved: Coming changes to the unittest module
 	 New and improved: Coming changes to the unittest module 	 New and improved: Coming changes to the unittest module
New and improved: Coming changes to the unittest modulePyCon Italia
 
Monitoraggio del Traffico di Rete Usando Python ed ntop
Monitoraggio del Traffico di Rete Usando Python ed ntopMonitoraggio del Traffico di Rete Usando Python ed ntop
Monitoraggio del Traffico di Rete Usando Python ed ntopPyCon Italia
 
Jython for embedded software validation
Jython for embedded software validationJython for embedded software validation
Jython for embedded software validationPyCon Italia
 
Foxgame introduzione all'apprendimento automatico
Foxgame introduzione all'apprendimento automaticoFoxgame introduzione all'apprendimento automatico
Foxgame introduzione all'apprendimento automaticoPyCon Italia
 
Django è pronto per l'Enterprise
Django è pronto per l'EnterpriseDjango è pronto per l'Enterprise
Django è pronto per l'EnterprisePyCon Italia
 
Crogioli, alambicchi e beute: dove mettere i vostri dati.
Crogioli, alambicchi e beute: dove mettere i vostri dati.Crogioli, alambicchi e beute: dove mettere i vostri dati.
Crogioli, alambicchi e beute: dove mettere i vostri dati.PyCon Italia
 
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & OrbitedComet web applications with Python, Django & Orbited
Comet web applications with Python, Django & OrbitedPyCon Italia
 
Cleanup and new optimizations in WPython 1.1
Cleanup and new optimizations in WPython 1.1Cleanup and new optimizations in WPython 1.1
Cleanup and new optimizations in WPython 1.1PyCon Italia
 

Plus de PyCon Italia (20)

Feed back report 2010
Feed back report 2010Feed back report 2010
Feed back report 2010
 
Spyppolare o non spyppolare
Spyppolare o non spyppolareSpyppolare o non spyppolare
Spyppolare o non spyppolare
 
zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"
zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"
zc.buildout: "Un modo estremamente civile per sviluppare un'applicazione"
 
Undici anni di lavoro con Python
Undici anni di lavoro con PythonUndici anni di lavoro con Python
Undici anni di lavoro con Python
 
socket e SocketServer: il framework per i server Internet in Python
socket e SocketServer: il framework per i server Internet in Pythonsocket e SocketServer: il framework per i server Internet in Python
socket e SocketServer: il framework per i server Internet in Python
 
Qt mobile PySide bindings
Qt mobile PySide bindingsQt mobile PySide bindings
Qt mobile PySide bindings
 
Python: ottimizzazione numerica algoritmi genetici
Python: ottimizzazione numerica algoritmi geneticiPython: ottimizzazione numerica algoritmi genetici
Python: ottimizzazione numerica algoritmi genetici
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Python in the browser
Python in the browserPython in the browser
Python in the browser
 
PyCuda: Come sfruttare la potenza delle schede video nelle applicazioni python
PyCuda: Come sfruttare la potenza delle schede video nelle applicazioni pythonPyCuda: Come sfruttare la potenza delle schede video nelle applicazioni python
PyCuda: Come sfruttare la potenza delle schede video nelle applicazioni python
 
OpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonOpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con Python
 
New and improved: Coming changes to the unittest module
 	 New and improved: Coming changes to the unittest module 	 New and improved: Coming changes to the unittest module
New and improved: Coming changes to the unittest module
 
Monitoraggio del Traffico di Rete Usando Python ed ntop
Monitoraggio del Traffico di Rete Usando Python ed ntopMonitoraggio del Traffico di Rete Usando Python ed ntop
Monitoraggio del Traffico di Rete Usando Python ed ntop
 
Jython for embedded software validation
Jython for embedded software validationJython for embedded software validation
Jython for embedded software validation
 
Foxgame introduzione all'apprendimento automatico
Foxgame introduzione all'apprendimento automaticoFoxgame introduzione all'apprendimento automatico
Foxgame introduzione all'apprendimento automatico
 
Effective EC2
Effective EC2Effective EC2
Effective EC2
 
Django è pronto per l'Enterprise
Django è pronto per l'EnterpriseDjango è pronto per l'Enterprise
Django è pronto per l'Enterprise
 
Crogioli, alambicchi e beute: dove mettere i vostri dati.
Crogioli, alambicchi e beute: dove mettere i vostri dati.Crogioli, alambicchi e beute: dove mettere i vostri dati.
Crogioli, alambicchi e beute: dove mettere i vostri dati.
 
Comet web applications with Python, Django & Orbited
Comet web applications with Python, Django & OrbitedComet web applications with Python, Django & Orbited
Comet web applications with Python, Django & Orbited
 
Cleanup and new optimizations in WPython 1.1
Cleanup and new optimizations in WPython 1.1Cleanup and new optimizations in WPython 1.1
Cleanup and new optimizations in WPython 1.1
 

Dernier

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 

Dernier (20)

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 

PyPy 1.2: snakes never crawled so fast

  • 1. PyPy 1.2: snakes never crawled so fast Antonio Cuni Armin Rigo Pycon Italia Qu4ttro May 8 2010 antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 1 / 35
  • 2. Outline PyPy 1.2: what’s new and status update Overview of the JIT Demo: how to use PyPy right now antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 1 / 35
  • 3. Part 0: What is PyPy? :-) Python interpreter written in Python Framework for developing dynamic languages etc. etc. From the user point of view An alternative to CPython with more features! antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 2 / 35
  • 4. Part 0: What is PyPy? :-) Python interpreter written in Python Framework for developing dynamic languages etc. etc. From the user point of view An alternative to CPython with more features! antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 2 / 35
  • 5. Part 1 What’s new and status update antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 3 / 35
  • 6. What’s new in PyPy 1.2 Released on March 12th, 2010 Main theme: speed JIT compiler speed.pypy.org Ubuntu packages antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 4 / 35
  • 7. Speed: PyPy vs CPython antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 5 / 35
  • 8. Speed: PyPy vs Psyco antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 6 / 35
  • 9. Speed: Demo Django application Mandelbrot fractal fished randomly on the net :-) Run both on CPython and PyPy django trunk! antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 7 / 35
  • 10. What works on PyPy Pure Python modules should Just Work (TM) django trunk twisted, nevow pylons bittorrent ... lot of standard modules __builtin__ __pypy__ _codecs _lsprof _minimal_curses _random _rawffi _socket _sre _weakref bz2 cStringIO crypt errno exceptions fcntl gc itertools marshal math md5 mmap operator parser posix pyexpat select sha signal struct symbol sys termios thread time token unicodedata zipimport zlib array binascii cPickle cmath collections ctypes datetime functools grp md5 pwd pyexpat sha sqlite3 syslog ctypes antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 8 / 35
  • 11. What works on PyPy Pure Python modules should Just Work (TM) django trunk twisted, nevow pylons bittorrent ... lot of standard modules __builtin__ __pypy__ _codecs _lsprof _minimal_curses _random _rawffi _socket _sre _weakref bz2 cStringIO crypt errno exceptions fcntl gc itertools marshal math md5 mmap operator parser posix pyexpat select sha signal struct symbol sys termios thread time token unicodedata zipimport zlib array binascii cPickle cmath collections ctypes datetime functools grp md5 pwd pyexpat sha sqlite3 syslog ctypes antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 8 / 35
  • 12. What does not work on PyPy Pure Python modules should Just Work (TM) ... unless they don’t :-) Programs that rely on CPython-specific behavior refcounting: open(’xxx’, ’w’).write(’stuff’) non-string keys in dict of types (try it!) exact naming of a list comprehension variable exact message matching in exception catching code ... Extension modules really? drum roll... antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 9 / 35
  • 13. What does not work on PyPy Pure Python modules should Just Work (TM) ... unless they don’t :-) Programs that rely on CPython-specific behavior refcounting: open(’xxx’, ’w’).write(’stuff’) non-string keys in dict of types (try it!) exact naming of a list comprehension variable exact message matching in exception catching code ... Extension modules really? drum roll... antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 9 / 35
  • 14. What does not work on PyPy Pure Python modules should Just Work (TM) ... unless they don’t :-) Programs that rely on CPython-specific behavior refcounting: open(’xxx’, ’w’).write(’stuff’) non-string keys in dict of types (try it!) exact naming of a list comprehension variable exact message matching in exception catching code ... Extension modules really? drum roll... antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 9 / 35
  • 15. What does not work on PyPy Pure Python modules should Just Work (TM) ... unless they don’t :-) Programs that rely on CPython-specific behavior refcounting: open(’xxx’, ’w’).write(’stuff’) non-string keys in dict of types (try it!) exact naming of a list comprehension variable exact message matching in exception catching code ... Extension modules really? drum roll... antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 9 / 35
  • 16. What does not work on PyPy Pure Python modules should Just Work (TM) ... unless they don’t :-) Programs that rely on CPython-specific behavior refcounting: open(’xxx’, ’w’).write(’stuff’) non-string keys in dict of types (try it!) exact naming of a list comprehension variable exact message matching in exception catching code ... Extension modules really? drum roll... antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 9 / 35
  • 17. cpyext CPython extension modules in PyPy pypy-c setup.py build still beta not 100% of CPython API is supported not included in PyPy 1.2 Known to work: wxPython (after a patch) _sre PyCrypto PIL antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 10 / 35
  • 18. wxPython on PyPy (1) antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 11 / 35
  • 19. wxPython on PyPy (2) antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 12 / 35
  • 20. PyPy 1.2.1 Coming soon Many bugfixes 27 issues reported after release of 1.2 beta version of cpyext antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 13 / 35
  • 21. Part 2: Just-in-Time compilation Snakes never crawled so fast antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 14 / 35
  • 22. Overview of implementations CPython Stackless Psyco Jython IronPython PyPy (without and with JIT) Unladen Swallow antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 15 / 35
  • 23. Demo antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 16 / 35
  • 24. Features it just works it may give good speed-ups (better than Psyco) it may have a few bugs left (Psyco too) it is not a hack (unlike Psyco) PyPy also has excellent memory usage half that of CPython for a program using several hunderds MBs antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 17 / 35
  • 25. Features it just works it may give good speed-ups (better than Psyco) it may have a few bugs left (Psyco too) it is not a hack (unlike Psyco) PyPy also has excellent memory usage half that of CPython for a program using several hunderds MBs antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 17 / 35
  • 26. Features it just works it may give good speed-ups (better than Psyco) it may have a few bugs left (Psyco too) it is not a hack (unlike Psyco) PyPy also has excellent memory usage half that of CPython for a program using several hunderds MBs antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 17 / 35
  • 27. What is a JIT CPython compiles the program source into bytecodes without a JIT, the bytecodes are then interpreted with a JIT, the bytecodes are further translated to machine code (assembler) antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 18 / 35
  • 28. What is a JIT (2) The translation can be: syntactic: translate the whole functions into machine code “the obvious way” e.g. Pyrex/Cython, Unladen Swallow not good performance, or needs tricks semantic: translate bits of the function just-in-time only used parts exploit runtime information (e.g. types) Psyco, PyPy antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 19 / 35
  • 29. What is a JIT (2) The translation can be: syntactic: translate the whole functions into machine code “the obvious way” e.g. Pyrex/Cython, Unladen Swallow not good performance, or needs tricks semantic: translate bits of the function just-in-time only used parts exploit runtime information (e.g. types) Psyco, PyPy antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 19 / 35
  • 30. What is a tracing JIT start by interpreting normally find loops as they are executed turn them into machine code 80% of the time is spent in 20% of the code antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 20 / 35
  • 31. What is a tracing JIT (history) tracing assembler (Dynamo, ~2000) tracing Java (~2005) tracing JavaScript (~2008) PyPy is a “tracing JIT generator” antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 21 / 35
  • 32. What is a tracing JIT (history) tracing assembler (Dynamo, ~2000) tracing Java (~2005) tracing JavaScript (~2008) PyPy is a “tracing JIT generator” antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 21 / 35
  • 33. The architecture of PyPy antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 22 / 35
  • 34. Speed of the PyPy JIT Python programs that are, or are not, nicely handled by the JIT: loops, even across many calls, are nicely handled loops with very many taken paths are not e.g. Python programs that look like interpreters typical in tracing JITs bad support so far for generators and recursion antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 23 / 35
  • 35. The optimizations we get != optimizations we wrote :-) removed frame handling local variables are in CPU registers or on the C stack but sys._getframe() works correctly “virtuals”: temporary objects are not constructed e = a + b + c + d and much more complex examples attribute and method lookups, etc. antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 24 / 35
  • 36. Example def g(a, b): ADD EAX, 1 if a < 5: # 2 CMP EAX, EBX return -1 JNL <guard 1> return a - b # 3 CMP EAX, 0 JL <guard 2> def f(x): MOV ECX, EAX total = 0 SUB ECX, EBX # 1 JO <guard 3> for i in range(x): ADD EDX, ECX d = g(i, x) JO <guard 4> total += d # 4 JMP antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 25 / 35
  • 37. Example def g(a, b): ADD EAX, 1 if a < 5: # 2 CMP EAX, EBX return -1 JNL <guard 1> return a - b # 3 CMP EAX, 0 JL <guard 2> def f(x): MOV ECX, EAX total = 0 SUB ECX, EBX # 1 JO <guard 3> for i in range(x): ADD EDX, ECX d = g(i, x) JO <guard 4> total += d # 4 JMP antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 25 / 35
  • 38. Practical results fast :-) so far, x86-32 only relatively easy to maintain (or port to x86-64, etc.) reminder: works transparently for any Python code or any language (Prolog JIT :-) at PPDP 2010) viable alternative to CPython antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 26 / 35
  • 39. Part 3 How to use PyPy right now antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 27 / 35
  • 40. Mandelbrot demo Works purely on PyPy Not always the case missing extension modules (cpyext mitigates the problem) libraries that rely on CPython details ... clear performance-critical part antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 28 / 35
  • 41. CPython and PyPy side by side CPython: runs the main application PyPy: subprocess, runs only the hotspots How do they communicate? execnet The Ring of Python, Holger Krekel, 9:00 oups, too late :-) antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 29 / 35
  • 42. Rendering (1) Mandelbrot def render(request): w = int(request.GET.get(’w’, 320)) h = int(request.GET.get(’h’, 240)) from py_mandel import mandelbrot img = mandelbrot(w, h) return HttpResponse(img, content_type="image/bmp") antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 30 / 35
  • 43. Rendering (2) Mandelbrot on PyPy def pypy_render(request): w = int(request.GET.get(’w’, 320)) h = int(request.GET.get(’h’, 240)) channel = pypy.remote_exec(""" from py_mandel import mandelbrot w, h = channel.receive() img = mandelbrot(w, h) channel.send(img) """) channel.send((w, h)) img = channel.receive() return HttpResponse(img, content_type="image/bmp") antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 31 / 35
  • 44. execnet setup At startup import execnet mygroup = execnet.Group() pypy = mygroup.makegateway("popen//python=pypy-c") pypy.remote_exec(""" import sys import os os.chdir("mandelbrot") sys.path.insert(0, ’’) """) antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 32 / 35
  • 45. Demo antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 33 / 35
  • 46. Benchmarks 1400 1200 1000 response time (ms) 800 pypy pypy+pypy 600 cpython cpython+pypy 400 200 0 0 2 4 6 8 10 12 requests/s antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 34 / 35
  • 47. Contact / Q&A Antonio Cuni: at http://merlinux.eu Armin Rigo: arigo (at) tunes.org Links: PyPy: http://pypy.org/ PyPy speed center: http://speed.pypy.org/ Blog: http://morepypy.blogspot.com antocuni, arigato (Pycon Italia Qu4ttro) PyPy 1.2 May 8 2010 35 / 35