SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
A better Python
  for the JVM
Tobias Ivarsson <tobias@thobe.org>
Hello, my name is...

• ...Tobias Ivarsson
• Jython Committer / Compiler geek
• Java developer at Neo Technology
  Ask me about our graph database - Neo4j
  (it works with Python)
• Overview of the “Advanced Compiler”
  project

• Performance figures
• Python / JVM mismatch
• Getting better
• Summary
• Overview of the “Advanced Compiler”
  project

• Performance figures
• Python / JVM mismatch
• Getting better
• Summary
Project motivation

• The ultimate goal is a faster Jython
• The new compiler is just a component to
  get there
• Focus is on representation of Python code
  on the JVM
What does Code
Representation include?
• Function/Method/Code object
  representation
• Call frame representation
 • Affects sys._getframe()
• Scopes. How to store locals and globals
• The representation of builtins
• Mapping from python attributes to the JVM
Compiler tool chain
                                                AST
Source code   Parser   AST   Analyzer                       Compiler
                                            Code Info
                                            per scope


                                The “spine” of the
                                compiler. The main part.
                                This is the same in any
                                compiler in Jython, and
                                similar to other systems,
                                CPython in particular, as
                                well.
Compiler tool chain
                                          AST
Source code   Parser   AST   Analyzer               Compiler     This is the structure of
                                                                 the compiler in Jython
                                        Code Info                today.
                                        per scope


                                                        Java
                                                     byte code


                  Jython
                 runtime
                  system                                     JVM
Compiler tool chain
                                          AST
Source code   Parser   AST   Analyzer               Compiler            IR   Transformer
                                        Code Info
                                        per scope
                                                                                  IR
                                                The advanced compiler
                                                adds t wo more steps
                                                to the compilation
                                                process.
                                                The analyzer and
                                                                              Codegen
                                                compiler step also
                                                                                   Java
                  Jython                        change.
                                                                                byte code

                 runtime
                  system                                           JVM
Compiler tool chain
                                                   AST
Source code        Parser       AST   Analyzer               Compiler      IR   Transformer
                                                 Code Info
This flexibility makes it                         per scope
possible to output many                                                              IR
different code formats.
Even bundle together multiple                                   Python
formats for one module.
                                                               byte code
                                                                                 Codegen
                                                                                      Java
                            Jython                                                 byte code
                                                             Interpreter
                           runtime
                            system                                     JVM
The Intermediate
     Representation

• “sea of nodes” style SSA
 • Control flow and data flow both
    modeled as edges between nodes
 • Simplifies instruction re-ordering
• Overview of the “Advanced Compiler”
  project

• Performance figures
• Python / JVM mismatch
• Getting better
• Summary
Parrotbench
• 7 tests, numbered b0-b6
• Test b1 omitted
 • Tests infinite recursion and expects
    recursion limit exception
 • Allocates objects while recursing
 • Not applicable for Jython
Running parrotbench
• Python 2.6 vs Jython 2.5 (trunk)
• Each test executes 3 times, minimum taken
• Total time of process execution, including
  startup also measured
• Jython also tested after JVM JIT warmup
 • Warmup for about 1 hour...
    110 iterations of each test
The tests
     (rough understanding)
• b0 parses python in python
• b2 computes pi
• b3 sorts random data
• b4 more parsing of python in python
• b5 tests performance of builtins
• b6 creates large simple lists/dicts
Python 2.6
        Test              Time (ms)
         b0                            1387
         b2                             160
         b3                             943
         b4                             438
         b5                             874
         b6                            1079
Total (incl.VM startup)               15085
Jython 2.5 (trunk)
        Test                Time (ms)            Time (ms)
                          (without JIT warmup)   (with JIT warmup)

         b0                            4090                 2099
         b2                             202                   107
         b3                            3612                 1629
         b4                            1095                   630
         b5                            3044                 2161
         b6                            2755                 2237
Total (incl.VM startup)              51702 Not applicable
CPython2.6 vs Jython2.5
           Python 2.6      Jython 2.5

60,000


45,000


30,000


15,000


    0
         Total runtime   Excluding VM startup
CPython2.6 vs Jython2.5
         b0           b2   b3           b4     b5        b6

15,000


11,250


 7,500


 3,750


    0
              Python 2.6        Jython 2.5   Jython with warmup
CPython2.6 vs Jython2.5
        Python 2.6        Jython 2.5        Jython with warmup

5,000


3,750


2,500


1,250


   0
         b0          b2      b3        b4         b5       b6
What about the
“Advanced Compiler”
• So far no speedup compared to the “old
  compiler”
• Slight slowdown due to extra compiler step
• Does provide a platform for adding
  optimizations
 • But none of these are implemented yet...
• Overview of the “Advanced Compiler”
  project

• Performance figures
• Python / JVM mismatch
• Getting better
• Summary
Call frames
• A lot of Python code depend on reflecting
  call frames
• Every JVM has call frames, but only expose
  them to debuggers
• Current Jython is naïve about how frames
  are propagated
  •   Simple prototyping hints at up to 2x boost
Extremely late binding

• Every binding can change
• The module scope is volatile
 • Even builtins can be overridden
Exception handling
• Exception type matching in Python is a
  sequential comparison.
• Exception type matching in the JVM is done
  on exact type by the VM.
• Exception types are specified as arbitrary
  expressions.
  • No way of mapping Python try/except
    directly to the JVM.
• Overview of the “Advanced Compiler”
  project

• Performance figures
• Python / JVM mismatch
• Getting better
• Summary
Call frames

• Analyze code - omit unnecessary frames
• Fall back to java frames for pdb et.al.
• Treat locals, globals, dir, exec, eval as special
• Pass state - avoid central stored state
• sys._getframe() is an implementation detail
Late binding

• Ignore it and provide a fail path
 • Inline builtins
    • Turn for i in range(...): ... into a java loop
 • Do direct invocations to members of the
     same module
Exception handling


• The same late binding optimizations
  + optimistic exception handler
  restructuring gets us far
Reaping the fruits of
    the future JVMs
• Invokedynamic can perform most optimistic
  direct calls and provide the fail path
• Interface injection makes java objects look
  like python objects
  • And improves integration between
    different dynamic languages even more
• The advanced compiler makes a perfect
  platform for integrating this
• Overview of the “Advanced Compiler”
  project

• Performance figures
• Python / JVM mismatch
• Getting better
• Summary
The “Advanced Jython
  compiler” project
• Not just a compiler - but everything close
  to the compiler - code representation
• A platform for moving forward
 • First and foremost an enabling tool
 • Actual improvement happens elsewhere
Performance
• Jython has decent performance
• On some benchmarks Jython is better
• For most “real applications” CPython is
  better
• Long running applications benefit from the
  JVM - Jython is for the server side
• We are only getting started...
Python / JVM mismatch
   - Getting better -

• Most of the problems comes from trying to
  mimic CPython to closely
• Future JVMs are a better match
• Optimistic optimizations are the way to go
Thank you!

Questions?
         Tobias Ivarsson
      <tobias@thobe.org>

Weitere ähnliche Inhalte

Was ist angesagt?

Python course syllabus
Python course syllabusPython course syllabus
Python course syllabusSugantha T
 
Pycon11: Python threads: Dive into GIL!
Pycon11: Python threads: Dive into GIL!Pycon11: Python threads: Dive into GIL!
Pycon11: Python threads: Dive into GIL!Chetan Giridhar
 
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
 
Python: the Project, the Language and the Style
Python: the Project, the Language and the StylePython: the Project, the Language and the Style
Python: the Project, the Language and the StyleJuan-Manuel Gimeno
 
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
 
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
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1Kanchilug
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythoneShikshak
 
a quick Introduction to PyPy
a quick Introduction to PyPya quick Introduction to PyPy
a quick Introduction to PyPyKai Aras
 
PyPy
PyPyPyPy
PyPyESUG
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An IntroductionSwarit Wadhe
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyTIB Academy
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners Sujith Kumar
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming pptismailmrribi
 
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
 

Was ist angesagt? (20)

Python course syllabus
Python course syllabusPython course syllabus
Python course syllabus
 
Pycon11: Python threads: Dive into GIL!
Pycon11: Python threads: Dive into GIL!Pycon11: Python threads: Dive into GIL!
Pycon11: Python threads: Dive into GIL!
 
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.
 
Python: the Project, the Language and the Style
Python: the Project, the Language and the StylePython: the Project, the Language and the Style
Python: the Project, the Language and the Style
 
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
 
Python Introduction | JNTUA | R19 | UNIT 1
Python Introduction | JNTUA | R19 | UNIT 1 Python Introduction | JNTUA | R19 | UNIT 1
Python Introduction | JNTUA | R19 | UNIT 1
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
 
Cython compiler
Cython compilerCython compiler
Cython compiler
 
Introduction python
Introduction pythonIntroduction python
Introduction python
 
Dalvik jit
Dalvik jitDalvik jit
Dalvik jit
 
An Introduction to PyPy
An Introduction to PyPyAn Introduction to PyPy
An Introduction to PyPy
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
a quick Introduction to PyPy
a quick Introduction to PyPya quick Introduction to PyPy
a quick Introduction to PyPy
 
PyPy
PyPyPyPy
PyPy
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academy
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming ppt
 
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
PythonPython
Python
 

Andere mochten auch

Exploiting Concurrency with Dynamic Languages
Exploiting Concurrency with Dynamic LanguagesExploiting Concurrency with Dynamic Languages
Exploiting Concurrency with Dynamic LanguagesTobias Lindaaker
 
A Better Python for the JVM
A Better Python for the JVMA Better Python for the JVM
A Better Python for the JVMTobias Lindaaker
 
[JavaOne 2011] Models for Concurrent Programming
[JavaOne 2011] Models for Concurrent Programming[JavaOne 2011] Models for Concurrent Programming
[JavaOne 2011] Models for Concurrent ProgrammingTobias Lindaaker
 
Choosing the right NOSQL database
Choosing the right NOSQL databaseChoosing the right NOSQL database
Choosing the right NOSQL databaseTobias Lindaaker
 
Persistent graphs in Python with Neo4j
Persistent graphs in Python with Neo4jPersistent graphs in Python with Neo4j
Persistent graphs in Python with Neo4jTobias Lindaaker
 
Building Applications with a Graph Database
Building Applications with a Graph DatabaseBuilding Applications with a Graph Database
Building Applications with a Graph DatabaseTobias Lindaaker
 
The Graph Traversal Programming Pattern
The Graph Traversal Programming PatternThe Graph Traversal Programming Pattern
The Graph Traversal Programming PatternMarko Rodriguez
 
An overview of Neo4j Internals
An overview of Neo4j InternalsAn overview of Neo4j Internals
An overview of Neo4j InternalsTobias Lindaaker
 
Introduction to NoSQL Databases
Introduction to NoSQL DatabasesIntroduction to NoSQL Databases
Introduction to NoSQL DatabasesDerek Stainer
 

Andere mochten auch (11)

Exploiting Concurrency with Dynamic Languages
Exploiting Concurrency with Dynamic LanguagesExploiting Concurrency with Dynamic Languages
Exploiting Concurrency with Dynamic Languages
 
A Better Python for the JVM
A Better Python for the JVMA Better Python for the JVM
A Better Python for the JVM
 
[JavaOne 2011] Models for Concurrent Programming
[JavaOne 2011] Models for Concurrent Programming[JavaOne 2011] Models for Concurrent Programming
[JavaOne 2011] Models for Concurrent Programming
 
JDK Power Tools
JDK Power ToolsJDK Power Tools
JDK Power Tools
 
Choosing the right NOSQL database
Choosing the right NOSQL databaseChoosing the right NOSQL database
Choosing the right NOSQL database
 
Persistent graphs in Python with Neo4j
Persistent graphs in Python with Neo4jPersistent graphs in Python with Neo4j
Persistent graphs in Python with Neo4j
 
Building Applications with a Graph Database
Building Applications with a Graph DatabaseBuilding Applications with a Graph Database
Building Applications with a Graph Database
 
NOSQL Overview
NOSQL OverviewNOSQL Overview
NOSQL Overview
 
The Graph Traversal Programming Pattern
The Graph Traversal Programming PatternThe Graph Traversal Programming Pattern
The Graph Traversal Programming Pattern
 
An overview of Neo4j Internals
An overview of Neo4j InternalsAn overview of Neo4j Internals
An overview of Neo4j Internals
 
Introduction to NoSQL Databases
Introduction to NoSQL DatabasesIntroduction to NoSQL Databases
Introduction to NoSQL Databases
 

Ähnlich wie A Better Python for the JVM

(ATS3-DEV05) Coding up Pipeline Pilot Components
(ATS3-DEV05) Coding up Pipeline Pilot Components(ATS3-DEV05) Coding up Pipeline Pilot Components
(ATS3-DEV05) Coding up Pipeline Pilot ComponentsBIOVIA
 
Micro servoces-choose-the-right-tools-programing-language
Micro servoces-choose-the-right-tools-programing-languageMicro servoces-choose-the-right-tools-programing-language
Micro servoces-choose-the-right-tools-programing-languageYouness Lasmak
 
Java Programming Environment,JDK,JRE,JVM.pptx
Java Programming Environment,JDK,JRE,JVM.pptxJava Programming Environment,JDK,JRE,JVM.pptx
Java Programming Environment,JDK,JRE,JVM.pptxsonalipatil225940
 
When Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the EnterpriseWhen Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the Enterprisebenbrowning
 
Javanotes ww8
Javanotes ww8Javanotes ww8
Javanotes ww8kumar467
 
Django On Jython (for Portland and Boulder Python user groups presentations)
Django On Jython (for Portland and Boulder Python user groups presentations)Django On Jython (for Portland and Boulder Python user groups presentations)
Django On Jython (for Portland and Boulder Python user groups presentations)Leonardo Soto
 
Modeling System Behaviors: A Better Paradigm on Prototyping
Modeling System Behaviors: A Better Paradigm on PrototypingModeling System Behaviors: A Better Paradigm on Prototyping
Modeling System Behaviors: A Better Paradigm on PrototypingDVClub
 
just in time JIT compiler
just in time JIT compilerjust in time JIT compiler
just in time JIT compilerMohit kumar
 
Devoxx 2009 Conference session Jbpm4 In Action
Devoxx 2009 Conference session Jbpm4 In ActionDevoxx 2009 Conference session Jbpm4 In Action
Devoxx 2009 Conference session Jbpm4 In ActionJoram Barrez
 
USAA Mono-to-Serverless.pdf
USAA Mono-to-Serverless.pdfUSAA Mono-to-Serverless.pdf
USAA Mono-to-Serverless.pdfRichHagarty
 
Java Performance & Profiling
Java Performance & ProfilingJava Performance & Profiling
Java Performance & ProfilingIsuru Perera
 
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)OpenBlend society
 
Ci of js and apex using jasmine, phantom js and drone io df14
Ci of js and apex using jasmine, phantom js and drone io   df14Ci of js and apex using jasmine, phantom js and drone io   df14
Ci of js and apex using jasmine, phantom js and drone io df14Kevin Poorman
 
Titanium Mobile: flexibility vs. performance
Titanium Mobile: flexibility vs. performanceTitanium Mobile: flexibility vs. performance
Titanium Mobile: flexibility vs. performanceomorandi
 
Jython in workflow and rules engines
Jython in workflow and rules enginesJython in workflow and rules engines
Jython in workflow and rules enginesVaclav Tunka
 

Ähnlich wie A Better Python for the JVM (20)

(ATS3-DEV05) Coding up Pipeline Pilot Components
(ATS3-DEV05) Coding up Pipeline Pilot Components(ATS3-DEV05) Coding up Pipeline Pilot Components
(ATS3-DEV05) Coding up Pipeline Pilot Components
 
Micro servoces-choose-the-right-tools-programing-language
Micro servoces-choose-the-right-tools-programing-languageMicro servoces-choose-the-right-tools-programing-language
Micro servoces-choose-the-right-tools-programing-language
 
Java Programming Environment,JDK,JRE,JVM.pptx
Java Programming Environment,JDK,JRE,JVM.pptxJava Programming Environment,JDK,JRE,JVM.pptx
Java Programming Environment,JDK,JRE,JVM.pptx
 
Turbo charging v8 engine
Turbo charging v8 engineTurbo charging v8 engine
Turbo charging v8 engine
 
When Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the EnterpriseWhen Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the Enterprise
 
Javanotes ww8
Javanotes ww8Javanotes ww8
Javanotes ww8
 
Java notes
Java notesJava notes
Java notes
 
JIT Compiler
JIT CompilerJIT Compiler
JIT Compiler
 
Django On Jython (for Portland and Boulder Python user groups presentations)
Django On Jython (for Portland and Boulder Python user groups presentations)Django On Jython (for Portland and Boulder Python user groups presentations)
Django On Jython (for Portland and Boulder Python user groups presentations)
 
Modeling System Behaviors: A Better Paradigm on Prototyping
Modeling System Behaviors: A Better Paradigm on PrototypingModeling System Behaviors: A Better Paradigm on Prototyping
Modeling System Behaviors: A Better Paradigm on Prototyping
 
just in time JIT compiler
just in time JIT compilerjust in time JIT compiler
just in time JIT compiler
 
Devoxx 2009 Conference session Jbpm4 In Action
Devoxx 2009 Conference session Jbpm4 In ActionDevoxx 2009 Conference session Jbpm4 In Action
Devoxx 2009 Conference session Jbpm4 In Action
 
USAA Mono-to-Serverless.pdf
USAA Mono-to-Serverless.pdfUSAA Mono-to-Serverless.pdf
USAA Mono-to-Serverless.pdf
 
Java Performance & Profiling
Java Performance & ProfilingJava Performance & Profiling
Java Performance & Profiling
 
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
 
Java Starting
Java StartingJava Starting
Java Starting
 
Ci of js and apex using jasmine, phantom js and drone io df14
Ci of js and apex using jasmine, phantom js and drone io   df14Ci of js and apex using jasmine, phantom js and drone io   df14
Ci of js and apex using jasmine, phantom js and drone io df14
 
Titanium Mobile: flexibility vs. performance
Titanium Mobile: flexibility vs. performanceTitanium Mobile: flexibility vs. performance
Titanium Mobile: flexibility vs. performance
 
Jvm fundamentals
Jvm fundamentalsJvm fundamentals
Jvm fundamentals
 
Jython in workflow and rules engines
Jython in workflow and rules enginesJython in workflow and rules engines
Jython in workflow and rules engines
 

Kürzlich hochgeladen

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Kürzlich hochgeladen (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

A Better Python for the JVM

  • 1. A better Python for the JVM Tobias Ivarsson <tobias@thobe.org>
  • 2. Hello, my name is... • ...Tobias Ivarsson • Jython Committer / Compiler geek • Java developer at Neo Technology Ask me about our graph database - Neo4j (it works with Python)
  • 3. • Overview of the “Advanced Compiler” project • Performance figures • Python / JVM mismatch • Getting better • Summary
  • 4. • Overview of the “Advanced Compiler” project • Performance figures • Python / JVM mismatch • Getting better • Summary
  • 5. Project motivation • The ultimate goal is a faster Jython • The new compiler is just a component to get there • Focus is on representation of Python code on the JVM
  • 6. What does Code Representation include? • Function/Method/Code object representation • Call frame representation • Affects sys._getframe() • Scopes. How to store locals and globals • The representation of builtins • Mapping from python attributes to the JVM
  • 7. Compiler tool chain AST Source code Parser AST Analyzer Compiler Code Info per scope The “spine” of the compiler. The main part. This is the same in any compiler in Jython, and similar to other systems, CPython in particular, as well.
  • 8. Compiler tool chain AST Source code Parser AST Analyzer Compiler This is the structure of the compiler in Jython Code Info today. per scope Java byte code Jython runtime system JVM
  • 9. Compiler tool chain AST Source code Parser AST Analyzer Compiler IR Transformer Code Info per scope IR The advanced compiler adds t wo more steps to the compilation process. The analyzer and Codegen compiler step also Java Jython change. byte code runtime system JVM
  • 10. Compiler tool chain AST Source code Parser AST Analyzer Compiler IR Transformer Code Info This flexibility makes it per scope possible to output many IR different code formats. Even bundle together multiple Python formats for one module. byte code Codegen Java Jython byte code Interpreter runtime system JVM
  • 11. The Intermediate Representation • “sea of nodes” style SSA • Control flow and data flow both modeled as edges between nodes • Simplifies instruction re-ordering
  • 12. • Overview of the “Advanced Compiler” project • Performance figures • Python / JVM mismatch • Getting better • Summary
  • 13. Parrotbench • 7 tests, numbered b0-b6 • Test b1 omitted • Tests infinite recursion and expects recursion limit exception • Allocates objects while recursing • Not applicable for Jython
  • 14. Running parrotbench • Python 2.6 vs Jython 2.5 (trunk) • Each test executes 3 times, minimum taken • Total time of process execution, including startup also measured • Jython also tested after JVM JIT warmup • Warmup for about 1 hour... 110 iterations of each test
  • 15. The tests (rough understanding) • b0 parses python in python • b2 computes pi • b3 sorts random data • b4 more parsing of python in python • b5 tests performance of builtins • b6 creates large simple lists/dicts
  • 16. Python 2.6 Test Time (ms) b0 1387 b2 160 b3 943 b4 438 b5 874 b6 1079 Total (incl.VM startup) 15085
  • 17. Jython 2.5 (trunk) Test Time (ms) Time (ms) (without JIT warmup) (with JIT warmup) b0 4090 2099 b2 202 107 b3 3612 1629 b4 1095 630 b5 3044 2161 b6 2755 2237 Total (incl.VM startup) 51702 Not applicable
  • 18. CPython2.6 vs Jython2.5 Python 2.6 Jython 2.5 60,000 45,000 30,000 15,000 0 Total runtime Excluding VM startup
  • 19. CPython2.6 vs Jython2.5 b0 b2 b3 b4 b5 b6 15,000 11,250 7,500 3,750 0 Python 2.6 Jython 2.5 Jython with warmup
  • 20. CPython2.6 vs Jython2.5 Python 2.6 Jython 2.5 Jython with warmup 5,000 3,750 2,500 1,250 0 b0 b2 b3 b4 b5 b6
  • 21. What about the “Advanced Compiler” • So far no speedup compared to the “old compiler” • Slight slowdown due to extra compiler step • Does provide a platform for adding optimizations • But none of these are implemented yet...
  • 22. • Overview of the “Advanced Compiler” project • Performance figures • Python / JVM mismatch • Getting better • Summary
  • 23. Call frames • A lot of Python code depend on reflecting call frames • Every JVM has call frames, but only expose them to debuggers • Current Jython is naïve about how frames are propagated • Simple prototyping hints at up to 2x boost
  • 24. Extremely late binding • Every binding can change • The module scope is volatile • Even builtins can be overridden
  • 25. Exception handling • Exception type matching in Python is a sequential comparison. • Exception type matching in the JVM is done on exact type by the VM. • Exception types are specified as arbitrary expressions. • No way of mapping Python try/except directly to the JVM.
  • 26. • Overview of the “Advanced Compiler” project • Performance figures • Python / JVM mismatch • Getting better • Summary
  • 27. Call frames • Analyze code - omit unnecessary frames • Fall back to java frames for pdb et.al. • Treat locals, globals, dir, exec, eval as special • Pass state - avoid central stored state • sys._getframe() is an implementation detail
  • 28. Late binding • Ignore it and provide a fail path • Inline builtins • Turn for i in range(...): ... into a java loop • Do direct invocations to members of the same module
  • 29. Exception handling • The same late binding optimizations + optimistic exception handler restructuring gets us far
  • 30. Reaping the fruits of the future JVMs • Invokedynamic can perform most optimistic direct calls and provide the fail path • Interface injection makes java objects look like python objects • And improves integration between different dynamic languages even more • The advanced compiler makes a perfect platform for integrating this
  • 31. • Overview of the “Advanced Compiler” project • Performance figures • Python / JVM mismatch • Getting better • Summary
  • 32. The “Advanced Jython compiler” project • Not just a compiler - but everything close to the compiler - code representation • A platform for moving forward • First and foremost an enabling tool • Actual improvement happens elsewhere
  • 33. Performance • Jython has decent performance • On some benchmarks Jython is better • For most “real applications” CPython is better • Long running applications benefit from the JVM - Jython is for the server side • We are only getting started...
  • 34. Python / JVM mismatch - Getting better - • Most of the problems comes from trying to mimic CPython to closely • Future JVMs are a better match • Optimistic optimizations are the way to go
  • 35. Thank you! Questions? Tobias Ivarsson <tobias@thobe.org>