SlideShare a Scribd company logo
Two Papers
Contribute to
Faster Python
Table of Contents
Faster CPython Project
Specializing Adaptive Interpreter
Copy-and-patch JIT Compilation
Faster Python Project
x5 Speed
Python
3.10
Python
3.11
Python
3.12
Python
3.13
Summarized in Implementation plan for speeding up CPython
⬆50
%
⬆50
%
⬆50
%
⬆50
%
Table of contents
Specialized Adaptive Interpreter
Motivated by Multi-level Quickening: The Key to Interpreter Performance
Multi-level Quickening: The Key to Interpreter Performance
Background
Interpreters for dynamically-typed programming languages are slow.
CPython
Interpreter
Python
Source
Code
Python
Virtual
Machine
Bytecode
Multi-level Quickening: The Key to Interpreter Performance
First-level Quickening: Type Feedback
Multi-level Quickening: The Key to Interpreter Performance
Second-level Quickening: Type Propagation
Multi-level Quickening: The Key to Interpreter Performance
Optimized Instruction Derivatives
i.e. Make instructions more optimized for machine data types
● Mapping Integer Numbers
○ uint64_t ? int64_t ? int32_t
● Mapping Floating Point Number
● Mapping Complex Numbers.
Multi-level Quickening: The Key to Interpreter Performance
Super-instructions:
concatenates frequently occurring sequences of interpreter instructions
>>> dis.dis(add_two)
1 0 RESUME 0
2 LOAD_FAST 0 (a)
4 LOAD_FAST 1 (b)
6 BINARY_OP 0 (+)
10 RETURN_VALUE
>>> dis.dis(add_two, adaptive=True)
1 0 RESUME 0
2 LOAD_FAST__LOAD_FAST 0 (a)
4 LOAD_FAST 1 (b)
6 BINARY_OP_ADD_FLOAT 0 (+)
10 RETURN_VALUE
>>> def add_two(a, b): return a + b
Multi-level Quickening: The Key to Interpreter Performance
Performance
Results
Quickening & Specialization in Reality
Python 3.11
● Specialization clicks in after 8
executions.
● 25% faster than Python 3.10.
Python 3.12
● Specialization clicks in after 2
executions.
● Special more new bytecodes.
Table of contents
Copy-and-patch JIT Compilation
Motivated by Copy-and-Patch Compilation: A fast compilation
algorithm for high-level languages and bytecode
Copy-and-Patch Compilation:
A fast compilation algorithm for high-level languages and bytecode
What’s JIT Compilation
● Just in time Compilation, only compile on demand when running for the 1st time.
● In contrast, compiled languages is using “Ahead of time”, compile before being used.
Copy-and-Patch Compilation:
A fast compilation algorithm for high-level languages and bytecode
Interpreting
Parse into
Bytecode
Execution
Copy-and-Patch JIT Compilation
Copy
Bytecode
Execution
Patch
arguments
Running a
function
several
times
Copy-and-Patch Compilation:
A fast compilation algorithm for high-level languages and bytecode
Normal Interpreting
Each time we run a function, CPython parse it into bytecodes, in a loop:
>>> def get_one():
... a = 1
... return a
>>> get_one()
>>> get_one()
1 0 RESUME 0
2 2 LOAD_CONST 1 (1)
4 STORE_FAST 0 (a)
3 6 LOAD_FAST 0 (a)
8 RETURN_VALUE
1 0 RESUME 0
2 2 LOAD_CONST 1 (1)
4 STORE_FAST 0 (a)
3 6 LOAD_FAST 0 (a)
8 RETURN_VALUE
Copy-and-Patch Compilation:
A fast compilation algorithm for high-level languages and bytecode
Copy-and-Patch JIT
>>> def get_one():
... a = 1
... return a
A function with the same
functionality, but written
in a lower language, e.g. C
or Assembly.
Table of contents
Caveat
Copy Instruction is kind of code generation, may expose security concerns.
iOS prohibits such dynamic code generation.
Copy-and-Patch Compilation in Reality
Table of contents
A basic JIT compiler will
be added in Python 3.13
(disabled in beta at the moment)
Take Away
● Upgrade to the latest Python version (official releases)
○ Save energy
○ Save money
○ Save environment
References
● Implementation plan for speeding up CPython
● Multi-Level Quickening: Ten Years Later
● Copy-and-Patch Compilation: A fast compilation algorithm for high-level languages and bytecode
● Python 3.13 gets a JIT

More Related Content

PDF
High-Performance Python
PDF
PyPy's approach to construct domain-specific language runtime
PDF
What's new in Python 3.11
PPTX
Fast Python: Master the Basics to Write Faster Code
PDF
Understanding PyPy - PyConEs 14
PDF
Expert Python Programming - Second Edition Michał Jaworski
PDF
Optimizing Python
PPTX
It is about IDLE Python Installation version 3.1.2
High-Performance Python
PyPy's approach to construct domain-specific language runtime
What's new in Python 3.11
Fast Python: Master the Basics to Write Faster Code
Understanding PyPy - PyConEs 14
Expert Python Programming - Second Edition Michał Jaworski
Optimizing Python
It is about IDLE Python Installation version 3.1.2

Similar to 社内勉強会資料_Two Papers Contribute to Faster Python.pdf (20)

PPTX
Ultimate Guide to Hire Dedicated Python Developers for Scalable Backend Solut...
PDF
«Python на острие бритвы: PyPy project» Александр Кошкин, Positive Technologies
PDF
Python高级编程(二)
PDF
High Performance Python Practical Performant Programming for Humans 2nd Editi...
PPTX
PPTX
What's new in Python 3.11
PDF
Harmonic Stack for Speed
ZIP
An Introduction to PyPy
PDF
PyPy London Demo Evening 2013
PDF
Cluj.py Meetup: Extending Python in C
PDF
High Performance Python 2nd Edition Micha Gorelick
PPT
Python Programming1.ppt
PPTX
Python-Development (1).pptx PYTHON PROGRAMMING
PDF
High Performance Python 2nd Edition Micha Gorelick Ian Ozsvald
PDF
Cython compiler
PDF
Python and Pytorch tutorial and walkthrough
ODP
Introduction to Python
PDF
Cython A Guide For Python Programmers 1st Edition Kurt W Smith
PPT
An Overview Of Python With Functional Programming
PPTX
Python-Yesterday Today Tomorrow(What's new?)
Ultimate Guide to Hire Dedicated Python Developers for Scalable Backend Solut...
«Python на острие бритвы: PyPy project» Александр Кошкин, Positive Technologies
Python高级编程(二)
High Performance Python Practical Performant Programming for Humans 2nd Editi...
What's new in Python 3.11
Harmonic Stack for Speed
An Introduction to PyPy
PyPy London Demo Evening 2013
Cluj.py Meetup: Extending Python in C
High Performance Python 2nd Edition Micha Gorelick
Python Programming1.ppt
Python-Development (1).pptx PYTHON PROGRAMMING
High Performance Python 2nd Edition Micha Gorelick Ian Ozsvald
Cython compiler
Python and Pytorch tutorial and walkthrough
Introduction to Python
Cython A Guide For Python Programmers 1st Edition Kurt W Smith
An Overview Of Python With Functional Programming
Python-Yesterday Today Tomorrow(What's new?)
Ad

More from NABLAS株式会社 (20)

PDF
勉強会資料_An Image is Worth More Than 16x16 Patches
PDF
輪読会資料_Miipher and Miipher2 .
PDF
社内勉強会資料_Chain of Thought .
PDF
hypermedia_system_revisit_roy_fielding .
PDF
π0.5: a Vision-Language-Action Model with Open-World Generalization
PDF
Transformers without Normalization .
PDF
社内勉強会資料_Data-Centric AI in The Age of Large Language Models
PDF
社内勉強会資料_Moshi_ a speech-text foundation model for real-time dialogue
PDF
社内勉強会資料_xGen-MM (BLIP-3): A Family of Open Large Multimodal Models
PDF
社内勉強会資料_Unsupervised Keypoints from Pretrained Diffusion Models
PDF
社内勉強会資料_Pruning in Large Language Models
PDF
社内勉強会資料_Human-level control through deep reinforcement learning
PDF
社内勉強会資料_Skywork-MoE .
PDF
勉強会資料_PointLLM .
PDF
Recipe Generation:Retrieval from Videos - Multi-Modal RecipeRag
PDF
社内勉強会資料_StepByStep Build own RAG. .
PDF
社内勉強会資料_History of LLaVA .
PDF
社内勉強会資料_AnyGPT_Unified Multimodal LLM with Discrete Sequence Modeling
PDF
社内勉強会資料_TransNeXt: Robust Foveal Visual Perception for Vision Transformers
PDF
社内勉強会資料_XTTS: a Massively Multilingual ZeroShot Text-to-Speech Model.pdf
勉強会資料_An Image is Worth More Than 16x16 Patches
輪読会資料_Miipher and Miipher2 .
社内勉強会資料_Chain of Thought .
hypermedia_system_revisit_roy_fielding .
π0.5: a Vision-Language-Action Model with Open-World Generalization
Transformers without Normalization .
社内勉強会資料_Data-Centric AI in The Age of Large Language Models
社内勉強会資料_Moshi_ a speech-text foundation model for real-time dialogue
社内勉強会資料_xGen-MM (BLIP-3): A Family of Open Large Multimodal Models
社内勉強会資料_Unsupervised Keypoints from Pretrained Diffusion Models
社内勉強会資料_Pruning in Large Language Models
社内勉強会資料_Human-level control through deep reinforcement learning
社内勉強会資料_Skywork-MoE .
勉強会資料_PointLLM .
Recipe Generation:Retrieval from Videos - Multi-Modal RecipeRag
社内勉強会資料_StepByStep Build own RAG. .
社内勉強会資料_History of LLaVA .
社内勉強会資料_AnyGPT_Unified Multimodal LLM with Discrete Sequence Modeling
社内勉強会資料_TransNeXt: Robust Foveal Visual Perception for Vision Transformers
社内勉強会資料_XTTS: a Massively Multilingual ZeroShot Text-to-Speech Model.pdf
Ad

Recently uploaded (20)

PDF
Business Analytics and business intelligence.pdf
PDF
Clinical guidelines as a resource for EBP(1).pdf
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPTX
Qualitative Qantitative and Mixed Methods.pptx
PDF
Lecture1 pattern recognition............
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPTX
Database Infoormation System (DBIS).pptx
PPTX
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
PPT
Quality review (1)_presentation of this 21
PPTX
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PPTX
Introduction to machine learning and Linear Models
Business Analytics and business intelligence.pdf
Clinical guidelines as a resource for EBP(1).pdf
Acceptance and paychological effects of mandatory extra coach I classes.pptx
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
Qualitative Qantitative and Mixed Methods.pptx
Lecture1 pattern recognition............
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
climate analysis of Dhaka ,Banglades.pptx
Database Infoormation System (DBIS).pptx
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
Quality review (1)_presentation of this 21
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
oil_refinery_comprehensive_20250804084928 (1).pptx
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
Introduction to machine learning and Linear Models

社内勉強会資料_Two Papers Contribute to Faster Python.pdf

  • 2. Table of Contents Faster CPython Project Specializing Adaptive Interpreter Copy-and-patch JIT Compilation
  • 4. x5 Speed Python 3.10 Python 3.11 Python 3.12 Python 3.13 Summarized in Implementation plan for speeding up CPython ⬆50 % ⬆50 % ⬆50 % ⬆50 % Table of contents
  • 5. Specialized Adaptive Interpreter Motivated by Multi-level Quickening: The Key to Interpreter Performance
  • 6. Multi-level Quickening: The Key to Interpreter Performance Background Interpreters for dynamically-typed programming languages are slow. CPython Interpreter Python Source Code Python Virtual Machine Bytecode
  • 7. Multi-level Quickening: The Key to Interpreter Performance First-level Quickening: Type Feedback
  • 8. Multi-level Quickening: The Key to Interpreter Performance Second-level Quickening: Type Propagation
  • 9. Multi-level Quickening: The Key to Interpreter Performance Optimized Instruction Derivatives i.e. Make instructions more optimized for machine data types ● Mapping Integer Numbers ○ uint64_t ? int64_t ? int32_t ● Mapping Floating Point Number ● Mapping Complex Numbers.
  • 10. Multi-level Quickening: The Key to Interpreter Performance Super-instructions: concatenates frequently occurring sequences of interpreter instructions >>> dis.dis(add_two) 1 0 RESUME 0 2 LOAD_FAST 0 (a) 4 LOAD_FAST 1 (b) 6 BINARY_OP 0 (+) 10 RETURN_VALUE >>> dis.dis(add_two, adaptive=True) 1 0 RESUME 0 2 LOAD_FAST__LOAD_FAST 0 (a) 4 LOAD_FAST 1 (b) 6 BINARY_OP_ADD_FLOAT 0 (+) 10 RETURN_VALUE >>> def add_two(a, b): return a + b
  • 11. Multi-level Quickening: The Key to Interpreter Performance Performance Results
  • 12. Quickening & Specialization in Reality Python 3.11 ● Specialization clicks in after 8 executions. ● 25% faster than Python 3.10. Python 3.12 ● Specialization clicks in after 2 executions. ● Special more new bytecodes. Table of contents
  • 13. Copy-and-patch JIT Compilation Motivated by Copy-and-Patch Compilation: A fast compilation algorithm for high-level languages and bytecode
  • 14. Copy-and-Patch Compilation: A fast compilation algorithm for high-level languages and bytecode What’s JIT Compilation ● Just in time Compilation, only compile on demand when running for the 1st time. ● In contrast, compiled languages is using “Ahead of time”, compile before being used.
  • 15. Copy-and-Patch Compilation: A fast compilation algorithm for high-level languages and bytecode Interpreting Parse into Bytecode Execution Copy-and-Patch JIT Compilation Copy Bytecode Execution Patch arguments Running a function several times
  • 16. Copy-and-Patch Compilation: A fast compilation algorithm for high-level languages and bytecode Normal Interpreting Each time we run a function, CPython parse it into bytecodes, in a loop: >>> def get_one(): ... a = 1 ... return a >>> get_one() >>> get_one() 1 0 RESUME 0 2 2 LOAD_CONST 1 (1) 4 STORE_FAST 0 (a) 3 6 LOAD_FAST 0 (a) 8 RETURN_VALUE 1 0 RESUME 0 2 2 LOAD_CONST 1 (1) 4 STORE_FAST 0 (a) 3 6 LOAD_FAST 0 (a) 8 RETURN_VALUE
  • 17. Copy-and-Patch Compilation: A fast compilation algorithm for high-level languages and bytecode Copy-and-Patch JIT >>> def get_one(): ... a = 1 ... return a A function with the same functionality, but written in a lower language, e.g. C or Assembly. Table of contents Caveat Copy Instruction is kind of code generation, may expose security concerns. iOS prohibits such dynamic code generation.
  • 18. Copy-and-Patch Compilation in Reality Table of contents A basic JIT compiler will be added in Python 3.13 (disabled in beta at the moment)
  • 19. Take Away ● Upgrade to the latest Python version (official releases) ○ Save energy ○ Save money ○ Save environment
  • 20. References ● Implementation plan for speeding up CPython ● Multi-Level Quickening: Ten Years Later ● Copy-and-Patch Compilation: A fast compilation algorithm for high-level languages and bytecode ● Python 3.13 gets a JIT