SlideShare a Scribd company logo
1 of 23
An Introduction
    to PyPy


          KiwiPyCon 2009

   Michael Hudson micahel@gmail.com
             Canonical Ltd.
What you’re in for
in the next 25 mins
  • Quick intro and motivation
  • Quick overview of architecture and current
    status
  • Introduction to features unique to PyPy,
    including the JIT
  • A little talk about what the future holds
What is PyPy?
• PyPy is:
 • An implementation of Python in Python
 • A very flexible compiler framework (with
    some features that are especially useful for
    implementing interpreters)
 • An open source project (MIT license)
• PyPy was partly EU-funded from 2005-2007
What we’ve got
• We can produce a binary that looks very
  much like CPython to the user
• Some, but not all, extension modules
  supported – socket, mmap, termios, …
• Can produce binary for CLR/.NET (watch
  out IronPython! :-) and JVM (ditto Jython…)
• Can also produce binaries with more
  features (stackless, JIT, …)
Motivation
• PyPy grew out of a desire to modify/extend
  the implementation of Python, for example to:
 • Increase performance (JIT compilation,
    better garbage collectors)
 • Ease porting (to new platforms like the
    JVM or CLI or to low memory situations)
 • Add expressiveness (stackless-style
    coroutines, logic programming)
Problems with
  CPython
• CPython is a fine implementation of Python
  but:
 • It’s written in C, which makes porting to,
    for example, the CLI hard
 • While psyco and stackless exist, they are
    very hard to maintain as Python evolves
 • Some implementation decisions are very
    hard to change (e.g. refcounting)
PyPy’s Big Idea
• Take a description of the Python
  programming language
• Analyze this description:
 • Decide whether to include stackless-like
    features or a JIT
 • Decide which GC to use
 • Decide the target platform
• Translate to a lower-level, efficient form
The PyPy platform
          Specification of the Python language

           Translation/Compiler Framework


    Python               Python             Python for an
running on JVM           with JIT          embedded device

       Python with                  Python just the way
  transactional memory                  you like it
How do you specify
the Python language?
   • The way we did it was to write an
     interpreter for Python in RPython – a subset
     of Python that is amenable to analysis
   • This allowed us to write unit tests for our
     specification/implementation that run on top
     of CPython
   • Can also test entire specification/
     implementation in same way
The Translation/
Compiler Framework
   • The compiler framework takes as input live
     Python objects (as opposed to source code)
   • It abstractly interprets the bytecode of
     functions to produce flow graphs
   • Further layers of abstract interpretation
     perform more analysis and gradually reduce
     the level of abstraction
   • Finally C or other source code is generated
If you have a
  hammer…
• We’d written this compiler framework, with
  only one expected non-trivial input (our
  Python interpreter)
• We realized that it would be suitable for
  implementations of other dynamically-typed
  programming languages
• Now have implementations of Prolog,
  JavaScript and Scheme (to varying extents)
The L×O×P problem
  This leads to one of PyPy’s meta-goals,
  ameliorating the so-called L×O×P problem:
  given
    • L dynamic languages
    • O target platforms
    • P implementation decisions
  we don’t want to have to write L×O×P different
  interpreters by hand.
The L×O×P problem
  • PyPy aims to reduce this to an L+O+P
    problem:
    • Implement L language front-ends
    • Write backends for O platforms
    • Take P implementation decisions
  • Then let the magic of PyPy™ tie it all
    together :-)
The exciting bit –
     the JIT
 • Most recent work has been on the second
   incarnation of the JIT
  • First incarnation sort of worked, but was
     completely crazy
  • It transformed the control flow graph of
     an interpreter into that of a compiler
 • Second attempt based on the idea of a
   “tracing JIT” like TraceMonkey or V8
The exciting bit –
     the JIT
 • It finds “traces” – frequently executed
   sequences of bytecode – in the program
 • Once a trace has been identified, it is
   interpreted in “tracing mode” where a
   record is kept of the low level operations
   that would be executed interpreting the
   bytecode
 • This is then compiled to machine code and
   executed
Status – Interpreter
  • PyPy’s Python interpreter supports 2.5.2 by
    default
  • 2.6 should be easy enough
  • No Py3K yet :-) (will be work, but not too
    insanely hard)
  • The “__pypy__” module includes a variety
    of mysterious and exciting things, depending
    on options supplied
Status – compiled
   interpreter
 • When compiled to (standalone) C with all
   the optimizations turned on, our interpreter
   varies from a little faster to about twice as
   slow than CPython
 • Can also build interpreters with threading
   and with stackless features
Status – backends
 • We currently have three complete backends:
  • C/POSIX (like CPython)
  • CLI (like IronPython)
  • JVM (like Jython)
Status – the JIT
• Usefulness of the JIT varies from program to
  program
  • Good examples are up to ten times faster
    than CPython
  • Bad ones still twice as slow
• Supports ia32, amd64 on the way
• Can also generate CLI bytecodes (which will
  then be JITted by Mono or the CLR)
Extra: sandboxing
 • Something completely different!
 • You can build PyPy’s Python interpreter in a
   way that can use limited CPU, memory and
   system calls
   • Works by running modified interpreter as
     a subprocess of a trusted “monitor”
   • All system calls in the interpreter are
     replaced with code to request the
     monitor perform the call
Future Work?
• JIT JIT JIT: making it make more practical:
 • speed up more programs by more
 • cap memory usage
• Easier platform integration
 • Particularly for JVM and CLI backends
• Implementations of other dynamic languages
  (which will get a JIT essentially for free)?
• Experiment with removing the GIL??
About the Project
 • Open source, of course (MIT license)
 • Read documentation:
      http://codespeak.net/pypy/

 • Project has a somewhat academic focus
   compared to most open source – lots of
   papers to read!
 • Come hang out in #pypy on freenode, post
   to pypy-dev@codespeak.net
Thanks for listening!




           Any Questions?

More Related Content

What's hot

DESIGN OF A CMOS BANDGAP REFERENCE WITH LOWTEMPERATURE COEFFICIENT AND HIGH P...
DESIGN OF A CMOS BANDGAP REFERENCE WITH LOWTEMPERATURE COEFFICIENT AND HIGH P...DESIGN OF A CMOS BANDGAP REFERENCE WITH LOWTEMPERATURE COEFFICIENT AND HIGH P...
DESIGN OF A CMOS BANDGAP REFERENCE WITH LOWTEMPERATURE COEFFICIENT AND HIGH P...VLSICS Design
 
SIP (Session Initiation Protocol)
SIP (Session Initiation Protocol)SIP (Session Initiation Protocol)
SIP (Session Initiation Protocol)KHNOG
 
Double Patterning (4/2 update)
Double Patterning (4/2 update)Double Patterning (4/2 update)
Double Patterning (4/2 update)Danny Luk
 
Aboutsip - intro to transactions and dialogs
Aboutsip - intro to transactions and dialogsAboutsip - intro to transactions and dialogs
Aboutsip - intro to transactions and dialogsJonas Borjesson
 
Network Traffic Analysis With Wireshark.pptx
Network Traffic Analysis With Wireshark.pptxNetwork Traffic Analysis With Wireshark.pptx
Network Traffic Analysis With Wireshark.pptxArifinChowdhury2
 
Cadence P-cell tutorial
Cadence P-cell tutorial Cadence P-cell tutorial
Cadence P-cell tutorial Michael Lee
 
CMOS Combinational_Logic_Circuits.pdf
CMOS Combinational_Logic_Circuits.pdfCMOS Combinational_Logic_Circuits.pdf
CMOS Combinational_Logic_Circuits.pdfSouravRoyElectronics
 
Physical design-complete
Physical design-completePhysical design-complete
Physical design-completeMurali Rai
 
Behavioral modeling of Clock/Data Recovery
Behavioral modeling of Clock/Data RecoveryBehavioral modeling of Clock/Data Recovery
Behavioral modeling of Clock/Data RecoveryArrow Devices
 
2019 3 testing and verification of vlsi design_sta
2019 3 testing and verification of vlsi design_sta2019 3 testing and verification of vlsi design_sta
2019 3 testing and verification of vlsi design_staUsha Mehta
 
2Overview of Primetime.pptx
2Overview of Primetime.pptx2Overview of Primetime.pptx
2Overview of Primetime.pptxShivangPanara
 

What's hot (20)

EMIR.pdf
EMIR.pdfEMIR.pdf
EMIR.pdf
 
DESIGN OF A CMOS BANDGAP REFERENCE WITH LOWTEMPERATURE COEFFICIENT AND HIGH P...
DESIGN OF A CMOS BANDGAP REFERENCE WITH LOWTEMPERATURE COEFFICIENT AND HIGH P...DESIGN OF A CMOS BANDGAP REFERENCE WITH LOWTEMPERATURE COEFFICIENT AND HIGH P...
DESIGN OF A CMOS BANDGAP REFERENCE WITH LOWTEMPERATURE COEFFICIENT AND HIGH P...
 
Crosstalk.pdf
Crosstalk.pdfCrosstalk.pdf
Crosstalk.pdf
 
SIP (Session Initiation Protocol)
SIP (Session Initiation Protocol)SIP (Session Initiation Protocol)
SIP (Session Initiation Protocol)
 
Matching concept in Microelectronics
Matching concept in MicroelectronicsMatching concept in Microelectronics
Matching concept in Microelectronics
 
bandgap ppt
bandgap pptbandgap ppt
bandgap ppt
 
Double Patterning (4/2 update)
Double Patterning (4/2 update)Double Patterning (4/2 update)
Double Patterning (4/2 update)
 
Aboutsip - intro to transactions and dialogs
Aboutsip - intro to transactions and dialogsAboutsip - intro to transactions and dialogs
Aboutsip - intro to transactions and dialogs
 
VLSI- Unit I
VLSI- Unit IVLSI- Unit I
VLSI- Unit I
 
PCIe DL_layer_3.0.1 (1)
PCIe DL_layer_3.0.1 (1)PCIe DL_layer_3.0.1 (1)
PCIe DL_layer_3.0.1 (1)
 
Network Traffic Analysis With Wireshark.pptx
Network Traffic Analysis With Wireshark.pptxNetwork Traffic Analysis With Wireshark.pptx
Network Traffic Analysis With Wireshark.pptx
 
Cadence P-cell tutorial
Cadence P-cell tutorial Cadence P-cell tutorial
Cadence P-cell tutorial
 
CMOS Combinational_Logic_Circuits.pdf
CMOS Combinational_Logic_Circuits.pdfCMOS Combinational_Logic_Circuits.pdf
CMOS Combinational_Logic_Circuits.pdf
 
Physical design-complete
Physical design-completePhysical design-complete
Physical design-complete
 
Behavioral modeling of Clock/Data Recovery
Behavioral modeling of Clock/Data RecoveryBehavioral modeling of Clock/Data Recovery
Behavioral modeling of Clock/Data Recovery
 
2019 3 testing and verification of vlsi design_sta
2019 3 testing and verification of vlsi design_sta2019 3 testing and verification of vlsi design_sta
2019 3 testing and verification of vlsi design_sta
 
Finfet
FinfetFinfet
Finfet
 
Powerplanning
PowerplanningPowerplanning
Powerplanning
 
Second order effects
Second order effectsSecond order effects
Second order effects
 
2Overview of Primetime.pptx
2Overview of Primetime.pptx2Overview of Primetime.pptx
2Overview of Primetime.pptx
 

Viewers also liked

a quick Introduction to PyPy
a quick Introduction to PyPya quick Introduction to PyPy
a quick Introduction to PyPyKai Aras
 
PyPy
PyPyPyPy
PyPyESUG
 
Adam_Mcconnell_SPR11_v3
Adam_Mcconnell_SPR11_v3Adam_Mcconnell_SPR11_v3
Adam_Mcconnell_SPR11_v3Adam McConnell
 
The 3 Models in the NGINX Microservices Reference Architecture
The 3 Models in the NGINX Microservices Reference ArchitectureThe 3 Models in the NGINX Microservices Reference Architecture
The 3 Models in the NGINX Microservices Reference ArchitectureNGINX, Inc.
 
REST vs. Messaging For Microservices
REST vs. Messaging For MicroservicesREST vs. Messaging For Microservices
REST vs. Messaging For MicroservicesEberhard Wolff
 

Viewers also liked (6)

a quick Introduction to PyPy
a quick Introduction to PyPya quick Introduction to PyPy
a quick Introduction to PyPy
 
PyPy
PyPyPyPy
PyPy
 
Adam_Mcconnell_SPR11_v3
Adam_Mcconnell_SPR11_v3Adam_Mcconnell_SPR11_v3
Adam_Mcconnell_SPR11_v3
 
Question 7
Question 7 Question 7
Question 7
 
The 3 Models in the NGINX Microservices Reference Architecture
The 3 Models in the NGINX Microservices Reference ArchitectureThe 3 Models in the NGINX Microservices Reference Architecture
The 3 Models in the NGINX Microservices Reference Architecture
 
REST vs. Messaging For Microservices
REST vs. Messaging For MicroservicesREST vs. Messaging For Microservices
REST vs. Messaging For Microservices
 

Similar to An Introduction to PyPy

Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python ProgrammingAkhil Kaushik
 
Introduction to Python Programing
Introduction to Python ProgramingIntroduction to Python Programing
Introduction to Python Programingsameer patil
 
Introduction to Python Programming Basics
Introduction  to  Python  Programming BasicsIntroduction  to  Python  Programming Basics
Introduction to Python Programming BasicsDhana malar
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1Kanchilug
 
Introduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfIntroduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfVaibhavKumarSinghkal
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unitmichaelaaron25322
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsHenry Schreiner
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.pptRehnawilson1
 
Python for students step by step guidance
Python for students step by step guidancePython for students step by step guidance
Python for students step by step guidanceMantoshKumar79
 
PYTHON FEATURES.pptx
PYTHON FEATURES.pptxPYTHON FEATURES.pptx
PYTHON FEATURES.pptxMaheShiva
 
4_Introduction to Python Programming.pptx
4_Introduction to Python Programming.pptx4_Introduction to Python Programming.pptx
4_Introduction to Python Programming.pptxGnanesh12
 
Pythonic doesn't mean slow!
Pythonic doesn't mean slow!Pythonic doesn't mean slow!
Pythonic doesn't mean slow!Ronan Lamy
 
Pyconsg2014 pyston
Pyconsg2014 pystonPyconsg2014 pyston
Pyconsg2014 pystonmasahitojp
 
Number of Computer Languages = 3
Number of Computer Languages = 3Number of Computer Languages = 3
Number of Computer Languages = 3Ram Sekhar
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughgabriellekuruvilla
 

Similar to An Introduction to PyPy (20)

Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Introduction to Python Programing
Introduction to Python ProgramingIntroduction to Python Programing
Introduction to Python Programing
 
Introduction to Python Programming Basics
Introduction  to  Python  Programming BasicsIntroduction  to  Python  Programming Basics
Introduction to Python Programming Basics
 
IPT 2.pptx
IPT 2.pptxIPT 2.pptx
IPT 2.pptx
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
 
Introduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfIntroduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdf
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python Extensions
 
1-ppt-python.ppt
1-ppt-python.ppt1-ppt-python.ppt
1-ppt-python.ppt
 
Four Python Pains
Four Python PainsFour Python Pains
Four Python Pains
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.ppt
 
Python for students step by step guidance
Python for students step by step guidancePython for students step by step guidance
Python for students step by step guidance
 
PYTHON FEATURES.pptx
PYTHON FEATURES.pptxPYTHON FEATURES.pptx
PYTHON FEATURES.pptx
 
4_Introduction to Python Programming.pptx
4_Introduction to Python Programming.pptx4_Introduction to Python Programming.pptx
4_Introduction to Python Programming.pptx
 
Pythonic doesn't mean slow!
Pythonic doesn't mean slow!Pythonic doesn't mean slow!
Pythonic doesn't mean slow!
 
Pyconsg2014 pyston
Pyconsg2014 pystonPyconsg2014 pyston
Pyconsg2014 pyston
 
Number of Computer Languages = 3
Number of Computer Languages = 3Number of Computer Languages = 3
Number of Computer Languages = 3
 
DSA Day 2 PPT.pdf
DSA Day 2 PPT.pdfDSA Day 2 PPT.pdf
DSA Day 2 PPT.pdf
 
Python programming 2nd
Python programming 2ndPython programming 2nd
Python programming 2nd
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 

Recently uploaded

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
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
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
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
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
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
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
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
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
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
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
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
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
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
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
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
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
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)
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

An Introduction to PyPy

  • 1. An Introduction to PyPy KiwiPyCon 2009 Michael Hudson micahel@gmail.com Canonical Ltd.
  • 2. What you’re in for in the next 25 mins • Quick intro and motivation • Quick overview of architecture and current status • Introduction to features unique to PyPy, including the JIT • A little talk about what the future holds
  • 3. What is PyPy? • PyPy is: • An implementation of Python in Python • A very flexible compiler framework (with some features that are especially useful for implementing interpreters) • An open source project (MIT license) • PyPy was partly EU-funded from 2005-2007
  • 4. What we’ve got • We can produce a binary that looks very much like CPython to the user • Some, but not all, extension modules supported – socket, mmap, termios, … • Can produce binary for CLR/.NET (watch out IronPython! :-) and JVM (ditto Jython…) • Can also produce binaries with more features (stackless, JIT, …)
  • 5. Motivation • PyPy grew out of a desire to modify/extend the implementation of Python, for example to: • Increase performance (JIT compilation, better garbage collectors) • Ease porting (to new platforms like the JVM or CLI or to low memory situations) • Add expressiveness (stackless-style coroutines, logic programming)
  • 6. Problems with CPython • CPython is a fine implementation of Python but: • It’s written in C, which makes porting to, for example, the CLI hard • While psyco and stackless exist, they are very hard to maintain as Python evolves • Some implementation decisions are very hard to change (e.g. refcounting)
  • 7. PyPy’s Big Idea • Take a description of the Python programming language • Analyze this description: • Decide whether to include stackless-like features or a JIT • Decide which GC to use • Decide the target platform • Translate to a lower-level, efficient form
  • 8. The PyPy platform Specification of the Python language Translation/Compiler Framework Python Python Python for an running on JVM with JIT embedded device Python with Python just the way transactional memory you like it
  • 9. How do you specify the Python language? • The way we did it was to write an interpreter for Python in RPython – a subset of Python that is amenable to analysis • This allowed us to write unit tests for our specification/implementation that run on top of CPython • Can also test entire specification/ implementation in same way
  • 10. The Translation/ Compiler Framework • The compiler framework takes as input live Python objects (as opposed to source code) • It abstractly interprets the bytecode of functions to produce flow graphs • Further layers of abstract interpretation perform more analysis and gradually reduce the level of abstraction • Finally C or other source code is generated
  • 11. If you have a hammer… • We’d written this compiler framework, with only one expected non-trivial input (our Python interpreter) • We realized that it would be suitable for implementations of other dynamically-typed programming languages • Now have implementations of Prolog, JavaScript and Scheme (to varying extents)
  • 12. The L×O×P problem This leads to one of PyPy’s meta-goals, ameliorating the so-called L×O×P problem: given • L dynamic languages • O target platforms • P implementation decisions we don’t want to have to write L×O×P different interpreters by hand.
  • 13. The L×O×P problem • PyPy aims to reduce this to an L+O+P problem: • Implement L language front-ends • Write backends for O platforms • Take P implementation decisions • Then let the magic of PyPy™ tie it all together :-)
  • 14. The exciting bit – the JIT • Most recent work has been on the second incarnation of the JIT • First incarnation sort of worked, but was completely crazy • It transformed the control flow graph of an interpreter into that of a compiler • Second attempt based on the idea of a “tracing JIT” like TraceMonkey or V8
  • 15. The exciting bit – the JIT • It finds “traces” – frequently executed sequences of bytecode – in the program • Once a trace has been identified, it is interpreted in “tracing mode” where a record is kept of the low level operations that would be executed interpreting the bytecode • This is then compiled to machine code and executed
  • 16. Status – Interpreter • PyPy’s Python interpreter supports 2.5.2 by default • 2.6 should be easy enough • No Py3K yet :-) (will be work, but not too insanely hard) • The “__pypy__” module includes a variety of mysterious and exciting things, depending on options supplied
  • 17. Status – compiled interpreter • When compiled to (standalone) C with all the optimizations turned on, our interpreter varies from a little faster to about twice as slow than CPython • Can also build interpreters with threading and with stackless features
  • 18. Status – backends • We currently have three complete backends: • C/POSIX (like CPython) • CLI (like IronPython) • JVM (like Jython)
  • 19. Status – the JIT • Usefulness of the JIT varies from program to program • Good examples are up to ten times faster than CPython • Bad ones still twice as slow • Supports ia32, amd64 on the way • Can also generate CLI bytecodes (which will then be JITted by Mono or the CLR)
  • 20. Extra: sandboxing • Something completely different! • You can build PyPy’s Python interpreter in a way that can use limited CPU, memory and system calls • Works by running modified interpreter as a subprocess of a trusted “monitor” • All system calls in the interpreter are replaced with code to request the monitor perform the call
  • 21. Future Work? • JIT JIT JIT: making it make more practical: • speed up more programs by more • cap memory usage • Easier platform integration • Particularly for JVM and CLI backends • Implementations of other dynamic languages (which will get a JIT essentially for free)? • Experiment with removing the GIL??
  • 22. About the Project • Open source, of course (MIT license) • Read documentation: http://codespeak.net/pypy/ • Project has a somewhat academic focus compared to most open source – lots of papers to read! • Come hang out in #pypy on freenode, post to pypy-dev@codespeak.net
  • 23. Thanks for listening! Any Questions?

Editor's Notes

  1. Have you got a big terminal and a pygame demo ready to go?