SlideShare a Scribd company logo
1 of 45
Speed up Python using
Rust
Kent Marete
@kentccs
maretekent
Table of content
What we will talk about today
• Why Python is awesome
• Python applications
• Speeding python using Rust library
• Examples – Sentry, Csv CLI application
• What is Rust?
• Why Rust?
• How Rust looks? –syntax, similarities
• Rust trifecta – Speed, Concurrency,
Safety
• Rust tooling
• Rust Pipeline
• Who is using Rust?
• Rust Meetup
• Q & A
What my talk is not
Introduction
• It’s not about which language is
great/ better
• Why a certain language is not
good
• Comparing languages
• Promoting a language
What my talk is …
Introduction
• Leverage on different technologies
• Python and Rust power
• Introduce Rust programming
language
Programming languages as Ingredients
Introduction
Why Python is awesome…
Why Python is awesome …
Why python
• Readability - resembles the English language
• Libraries - Python has been around for over 20 years
• Community - has user groups everywhere
• Dynamically typed language – no types declaring variable
• Simple syntax – less debugging
• One liner – elegant 1-liner solution i.e. x, y = y, x
• Intuitive data structures – List, tuples, dictionaries, mixed
data types
Python Applications
Python applications
Why python
web
Scientific
Python applications
Why python
DesktopGUIs
Software Development
Business
Applications
Speed Python using Rust
What is Rust?
• Systems programming language
• Trifecta – Speed, concurrency and Safety
• Rust is considered a C-like language with more features – advantage
History
• Graydon Hoare dev 2006
• Mozilla starts sponsoring Rust in 2009
• Version 1.0.0 (2015-)
• > 19,567 crates – libraries & 584,987,337 Downloads
• >2,211 contributors on Github. Compiler
• Big areas: game dev, operating systems, web development, block chain
Csvterm CLI project
Matt Gathu
@swissgathu
About csvterm cli project
Csvterm cli project
• Count the number of rows in the CSV
data
• Show the last N rows of CSV data.
• Search CSV data using regex
• Sort CSV data
Commands
 sort
 search
 count
 head
 headers
Demo time
Csvterm cli project
Bar graph showing sort in Python vs Python with Rust lib
Line graph showing sort in Python vs Python with Rust lib
Bar graph showing big csv file sort in Python vs Python with Rust lib
Rsort: 35 secs
Sort: 6 minutes 22.551s
Csvterm CLI project
Code Anatomy
Extending Python with C
Why python
Useful libraries:
• Cffi
Extending Python with Rust
Extending Python with Rust
Why python
Useful libraries:
• Cffi
• Milksnake
Other libs
• Click
• terminaltables
Procedure
1. build the Rust code into libs (crate)
2. build a new crate that exposes a nice C-ABI
3. use cbindgen to generate C headers
4. use Milksnake to automatically generate low-level
bindings from this crate and headers
5. generate high-level Python wrappers around the low-
level bindings
Extending Python with Rust
Why python
Procedure
1. build the Rust code into libs (crate)
2. build a new crate that exposes a nice C-ABI
3. Use cbindgen to generate C headers
4. use Milksnake to automatically generate low-level
bindings from this crate and headers
5. generate high-level Python wrappers around the low-
level bindings
cargo new crate_name --lib
cargo new crate_name --bin
Extending Python with Rust
Why python
Procedure
1. build the Rust code into libs
(crate)
2. build a new crate that exposes
a nice C-ABI
3. Use cbindgen to generate C
headers
4. use Milksnake to
automatically generate low-
level bindings from this crate
and headers
5. generate high-level Python
wrappers around the low-
level bindings
Extending Python with Rust
To explain further
Extending Python with Rust
Why python
Procedure
1. build the Rust code into libs (crate)
2. build a new crate that exposes a nice C-ABI
3. Use cbindgen to generate C headers
4. use Milksnake to automatically generate low-level
bindings from this crate and headers
5. generate high-level Python wrappers around the low-
level bindings
Extending Python with Rust
Why python
Procedure
1. build the Rust code into libs (crate)
2. build a new crate that exposes a nice C-ABI
3. Use cbindgen to generate C headers
4. use Milksnake to automatically generate low-level
bindings from this crate and headers
5. generate high-level Python wrappers around the low-
level bindings
Extending Python with Rust
Why python
Procedure
1. build the Rust code into libs
(crate)
2. build a new crate that
exposes a nice C-ABI
3. Use cbindgen to generate C
headers
4. use Milksnake to
automatically generate low-
level bindings from this crate
and headers
5. generate high-level Python
wrappers around the low-
level bindings
Sentry
Sentry extends Python with Rust
Fixed performance with Rust
Sentry extends Python with Rust
CPUs processing
Sentry extends Python with Rust
The average processing time
Why Rust?
Why Rust?
 Speed
 Rust has great functionality – raw binary data
 Reliability – rare to break, once it runs
 Control
 limited resources
 Concurrency
 Type inference - let b= 5u8; let a=5;
 High level abstraction – minimizes code
How Rust looks?
How Rust looks?
Safety, Speed and
Concurrency
• Run piece of code
concurrently
• leverages ownership
safety
• message-passing
between threads
• One data owner at a
time
• more than one pointer
to the same memory
no changing of the
data
• Uses Ownership and
borrowing concept
• No Garbage Collection
• LLVM - compiler
infrastructure
• Zero Cost
Abstractions
• Minimal Runtime – No
GC, can compile
without stdlib
Speed, Safety and Concurrency
SUB-HEADING
Rust tooling & pipeline
Rust tooling and pipeline
 Cargo
 rustup
 Rustfmt
 Clippy
RFC Nightly Beta Stable
Who is using Rust?
https://www.rust-lang.org/en-US/friends.html
Armin Ronacher
Rust Nairobi User group Meetup
https://www.meetup.com/Rust-Nairobi/
https://twitter.com/RustNairobi
https://github.com/rust-nairobi/
Q & A
Pyconke2018

More Related Content

Similar to Pyconke2018

Scylla Summit 2022: Learning Rust the Hard Way for a Production Kafka+ScyllaD...
Scylla Summit 2022: Learning Rust the Hard Way for a Production Kafka+ScyllaD...Scylla Summit 2022: Learning Rust the Hard Way for a Production Kafka+ScyllaD...
Scylla Summit 2022: Learning Rust the Hard Way for a Production Kafka+ScyllaD...ScyllaDB
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and AbstractionsMetosin Oy
 
Markup languages and warp-speed documentation
Markup languages and warp-speed documentationMarkup languages and warp-speed documentation
Markup languages and warp-speed documentationLois Patterson
 
Lois Patterson: Markup Languages and Warp-Speed Documentation
Lois Patterson:  Markup Languages and Warp-Speed DocumentationLois Patterson:  Markup Languages and Warp-Speed Documentation
Lois Patterson: Markup Languages and Warp-Speed DocumentationJack Molisani
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.pptRehnawilson1
 
High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014Derek Collison
 
Python for security professionals by katoh jeremiah [py con ng 2018]
Python for security professionals by katoh jeremiah [py con ng 2018]Python for security professionals by katoh jeremiah [py con ng 2018]
Python for security professionals by katoh jeremiah [py con ng 2018]jerrykatoh
 
AI & Machine Learning Pipelines with Knative
AI & Machine Learning Pipelines with KnativeAI & Machine Learning Pipelines with Knative
AI & Machine Learning Pipelines with KnativeAnimesh Singh
 
20120524 english lt2_pythontoolsfortesting
20120524 english lt2_pythontoolsfortesting20120524 english lt2_pythontoolsfortesting
20120524 english lt2_pythontoolsfortestingKazuhiro Oinuma
 
Module: Beyond bitswap
Module: Beyond bitswapModule: Beyond bitswap
Module: Beyond bitswapIoannis Psaras
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unitmichaelaaron25322
 
OpenSAF Symposium_Python Bindings_9.21.11
OpenSAF Symposium_Python Bindings_9.21.11OpenSAF Symposium_Python Bindings_9.21.11
OpenSAF Symposium_Python Bindings_9.21.11OpenSAF Foundation
 
Introduction to python 3 2nd round
Introduction to python 3   2nd roundIntroduction to python 3   2nd round
Introduction to python 3 2nd roundYouhei Sakurai
 
python presntation 2.pptx
python presntation 2.pptxpython presntation 2.pptx
python presntation 2.pptxArpittripathi45
 
From a student to an apache committer practice of apache io tdb
From a student to an apache committer  practice of apache io tdbFrom a student to an apache committer  practice of apache io tdb
From a student to an apache committer practice of apache io tdbjixuan1989
 
Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Fwdays
 
Take Kafka-on-Pulsar to Production at Internet Scale: Improvements Made for P...
Take Kafka-on-Pulsar to Production at Internet Scale: Improvements Made for P...Take Kafka-on-Pulsar to Production at Internet Scale: Improvements Made for P...
Take Kafka-on-Pulsar to Production at Internet Scale: Improvements Made for P...StreamNative
 

Similar to Pyconke2018 (20)

PySide
PySidePySide
PySide
 
Scylla Summit 2022: Learning Rust the Hard Way for a Production Kafka+ScyllaD...
Scylla Summit 2022: Learning Rust the Hard Way for a Production Kafka+ScyllaD...Scylla Summit 2022: Learning Rust the Hard Way for a Production Kafka+ScyllaD...
Scylla Summit 2022: Learning Rust the Hard Way for a Production Kafka+ScyllaD...
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and Abstractions
 
Markup languages and warp-speed documentation
Markup languages and warp-speed documentationMarkup languages and warp-speed documentation
Markup languages and warp-speed documentation
 
Lois Patterson: Markup Languages and Warp-Speed Documentation
Lois Patterson:  Markup Languages and Warp-Speed DocumentationLois Patterson:  Markup Languages and Warp-Speed Documentation
Lois Patterson: Markup Languages and Warp-Speed Documentation
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.ppt
 
High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014
 
Introduction_to_Python.pptx
Introduction_to_Python.pptxIntroduction_to_Python.pptx
Introduction_to_Python.pptx
 
Python for security professionals by katoh jeremiah [py con ng 2018]
Python for security professionals by katoh jeremiah [py con ng 2018]Python for security professionals by katoh jeremiah [py con ng 2018]
Python for security professionals by katoh jeremiah [py con ng 2018]
 
AI & Machine Learning Pipelines with Knative
AI & Machine Learning Pipelines with KnativeAI & Machine Learning Pipelines with Knative
AI & Machine Learning Pipelines with Knative
 
20120524 english lt2_pythontoolsfortesting
20120524 english lt2_pythontoolsfortesting20120524 english lt2_pythontoolsfortesting
20120524 english lt2_pythontoolsfortesting
 
Module: Beyond bitswap
Module: Beyond bitswapModule: Beyond bitswap
Module: Beyond bitswap
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
 
PyData Boston 2013
PyData Boston 2013PyData Boston 2013
PyData Boston 2013
 
OpenSAF Symposium_Python Bindings_9.21.11
OpenSAF Symposium_Python Bindings_9.21.11OpenSAF Symposium_Python Bindings_9.21.11
OpenSAF Symposium_Python Bindings_9.21.11
 
Introduction to python 3 2nd round
Introduction to python 3   2nd roundIntroduction to python 3   2nd round
Introduction to python 3 2nd round
 
python presntation 2.pptx
python presntation 2.pptxpython presntation 2.pptx
python presntation 2.pptx
 
From a student to an apache committer practice of apache io tdb
From a student to an apache committer  practice of apache io tdbFrom a student to an apache committer  practice of apache io tdb
From a student to an apache committer practice of apache io tdb
 
Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"
 
Take Kafka-on-Pulsar to Production at Internet Scale: Improvements Made for P...
Take Kafka-on-Pulsar to Production at Internet Scale: Improvements Made for P...Take Kafka-on-Pulsar to Production at Internet Scale: Improvements Made for P...
Take Kafka-on-Pulsar to Production at Internet Scale: Improvements Made for P...
 

Recently uploaded

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 

Recently uploaded (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

Pyconke2018

  • 1. Speed up Python using Rust Kent Marete @kentccs maretekent
  • 2. Table of content What we will talk about today • Why Python is awesome • Python applications • Speeding python using Rust library • Examples – Sentry, Csv CLI application • What is Rust? • Why Rust? • How Rust looks? –syntax, similarities • Rust trifecta – Speed, Concurrency, Safety • Rust tooling • Rust Pipeline • Who is using Rust? • Rust Meetup • Q & A
  • 3. What my talk is not Introduction • It’s not about which language is great/ better • Why a certain language is not good • Comparing languages • Promoting a language
  • 4. What my talk is … Introduction • Leverage on different technologies • Python and Rust power • Introduce Rust programming language
  • 5. Programming languages as Ingredients Introduction
  • 6. Why Python is awesome…
  • 7. Why Python is awesome … Why python • Readability - resembles the English language • Libraries - Python has been around for over 20 years • Community - has user groups everywhere • Dynamically typed language – no types declaring variable • Simple syntax – less debugging • One liner – elegant 1-liner solution i.e. x, y = y, x • Intuitive data structures – List, tuples, dictionaries, mixed data types
  • 10. Python applications Why python DesktopGUIs Software Development Business Applications
  • 12. What is Rust? • Systems programming language • Trifecta – Speed, concurrency and Safety • Rust is considered a C-like language with more features – advantage
  • 13. History • Graydon Hoare dev 2006 • Mozilla starts sponsoring Rust in 2009 • Version 1.0.0 (2015-) • > 19,567 crates – libraries & 584,987,337 Downloads • >2,211 contributors on Github. Compiler • Big areas: game dev, operating systems, web development, block chain
  • 14. Csvterm CLI project Matt Gathu @swissgathu
  • 15. About csvterm cli project Csvterm cli project • Count the number of rows in the CSV data • Show the last N rows of CSV data. • Search CSV data using regex • Sort CSV data Commands  sort  search  count  head  headers
  • 17. Bar graph showing sort in Python vs Python with Rust lib
  • 18. Line graph showing sort in Python vs Python with Rust lib
  • 19. Bar graph showing big csv file sort in Python vs Python with Rust lib Rsort: 35 secs Sort: 6 minutes 22.551s
  • 21. Extending Python with C Why python Useful libraries: • Cffi
  • 23. Extending Python with Rust Why python Useful libraries: • Cffi • Milksnake Other libs • Click • terminaltables Procedure 1. build the Rust code into libs (crate) 2. build a new crate that exposes a nice C-ABI 3. use cbindgen to generate C headers 4. use Milksnake to automatically generate low-level bindings from this crate and headers 5. generate high-level Python wrappers around the low- level bindings
  • 24. Extending Python with Rust Why python Procedure 1. build the Rust code into libs (crate) 2. build a new crate that exposes a nice C-ABI 3. Use cbindgen to generate C headers 4. use Milksnake to automatically generate low-level bindings from this crate and headers 5. generate high-level Python wrappers around the low- level bindings cargo new crate_name --lib cargo new crate_name --bin
  • 25. Extending Python with Rust Why python Procedure 1. build the Rust code into libs (crate) 2. build a new crate that exposes a nice C-ABI 3. Use cbindgen to generate C headers 4. use Milksnake to automatically generate low- level bindings from this crate and headers 5. generate high-level Python wrappers around the low- level bindings
  • 26. Extending Python with Rust To explain further
  • 27. Extending Python with Rust Why python Procedure 1. build the Rust code into libs (crate) 2. build a new crate that exposes a nice C-ABI 3. Use cbindgen to generate C headers 4. use Milksnake to automatically generate low-level bindings from this crate and headers 5. generate high-level Python wrappers around the low- level bindings
  • 28. Extending Python with Rust Why python Procedure 1. build the Rust code into libs (crate) 2. build a new crate that exposes a nice C-ABI 3. Use cbindgen to generate C headers 4. use Milksnake to automatically generate low-level bindings from this crate and headers 5. generate high-level Python wrappers around the low- level bindings
  • 29. Extending Python with Rust Why python Procedure 1. build the Rust code into libs (crate) 2. build a new crate that exposes a nice C-ABI 3. Use cbindgen to generate C headers 4. use Milksnake to automatically generate low- level bindings from this crate and headers 5. generate high-level Python wrappers around the low- level bindings
  • 31. Sentry extends Python with Rust Fixed performance with Rust
  • 32. Sentry extends Python with Rust CPUs processing
  • 33. Sentry extends Python with Rust The average processing time
  • 35. Why Rust?  Speed  Rust has great functionality – raw binary data  Reliability – rare to break, once it runs  Control  limited resources  Concurrency  Type inference - let b= 5u8; let a=5;  High level abstraction – minimizes code
  • 39. • Run piece of code concurrently • leverages ownership safety • message-passing between threads • One data owner at a time • more than one pointer to the same memory no changing of the data • Uses Ownership and borrowing concept • No Garbage Collection • LLVM - compiler infrastructure • Zero Cost Abstractions • Minimal Runtime – No GC, can compile without stdlib Speed, Safety and Concurrency SUB-HEADING
  • 40. Rust tooling & pipeline
  • 41. Rust tooling and pipeline  Cargo  rustup  Rustfmt  Clippy RFC Nightly Beta Stable
  • 42. Who is using Rust? https://www.rust-lang.org/en-US/friends.html Armin Ronacher
  • 43. Rust Nairobi User group Meetup https://www.meetup.com/Rust-Nairobi/ https://twitter.com/RustNairobi https://github.com/rust-nairobi/
  • 44. Q & A

Editor's Notes

  1. How could we leverage on different technologies to solve our issues and achieve solutions in optimal way
  2. Web and Internet Development – django, flask, pyramid, bottle Scientific and Numeric – SciPy, Pandas- Data science Education – Deep Learning- Natural Language Processing - like detect spam emails, write poetry, spin articles, and group together similar words. Scripting & Analysis – Machine learning
  3. Desktop GUIs – pyqt, Tk Software Development – build control Business Applications – ERPs
  4. Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety. Avoiding data races. Rust is a systems programming language focused on three goals: safety, speed, and concurrency. Segfaults are caused by a program trying to read or write an illegal memory location. A data race occurs when: two or more threads in a single process access the same memory location concurrently, and. at least one of the accesses is for writing, and. the threads are not using any exclusive locks to control their accesses to that memory.
  5. Abstract Machine Model : C Data types : C, SML, OCaml, Lisp, Limbo Optional Bindings : Swift Hygienic Macros : Scheme Functional Programming : Haskell, OCaml, F# Attributes : ECMA-335 Memory Model and Memory Management : C++, ML Kit, Cyclone Type Classes : Haskell Crate : Assembly in the ECMA-335 CLI model Channels and Concurrency : Newsqueak, Alef, Limbo Message passing and Thread failure : Erlang
  6. C Foreign Function Interface - provides a simple to use mechanism for interfacing with C from both CPython and PyPy. It supports two modes: an inline ABI compatibility mode an inline ABI compatibility mode (example provided below)  which allows you to dynamically load and run functions from executable modules (essentially exposing the same functionality as LoadLibrary or dlopen) --------------------------------- ctypes is the de facto library for interfacing with C/C++ from CPython, and it provides not only full access to the native C interface of most major operating systems (e.g., kernel32 on Windows, or libc on *nix), but also provides support for loading and interfacing with dynamic libraries, such as DLLs or shared objects at runtime. What is ABI: application binary interface (ABI) is an interface between two binary program modules; often, one of these modules is a library or operating system facility, and the other is a program that is being run by a user.
  7. This is using ctypes Load dynamic library in rust Generally import the function as it is pass in the arguments/ params Does computation inside rust and give the results
  8. These are some useful libraries Milksnake is an extension for setuptools that allows you to distribute dynamic linked libraries in Python wheels in the most portable way imaginable. ========================= Dylib – dynamic library What is ABI: application binary interface (ABI) is an interface between two binary program modules; often, one of these modules is a library or operating system facility, and the other is a program that is being run by a user.
  9. Lib creates a crate (reusable library) Bin creates a binary project
  10. Sometimes, your Rust code may need to interact with code written in another language. Because that is the way we interact with the python through c. To do this, Rust has a keyword, extern, that facilitates creating and using a Foreign Function Interface (FFI). No_mangle is used in mangling mangling is the encoding of function and variable names into unique names so that linkers can separate common names in the language. Linkers - a program used with a compiler or assembler to provide links to the libraries needed for an executable program What is ABI: application binary interface (ABI) is an interface between two binary program modules; often, one of these modules is a library or operating system facility, and the other is a program that is being run by a user.
  11. Cargo new –bin <name-project>
  12. Cargo new –bin <name-project>
  13. Cargo new –bin <name-project>
  14. Sentry - error tracking that helps developers monitor and fix crashes in real time.
  15. cut down the processing time from >20 seconds to <0.5 sec. This meant that even ignoring any optimizations, just replacing Python with Rust could relieve our chokepoint CPUs efficiently processing, Their worst source map times reduced to a tenth of their original time.
  16. Actual graph of CPU processing  CPUs efficiently processing
  17. - The average processing time reduced to ~400ms.
  18. Rust has great functionality which we don’t find in python – raw binary data If you needed to control of your machine and make most of your resource in the past you had one language C/ C++. Great power comes with great responsibility. Any small mistake can have catastrophic consequences or do the unexpected. The best scenario being a crash or worse open you to great security vulnerability. This is why systems programming has come to have horror of being a super hero. - Rust focuses on minimal core and extended by powerful libraries - Making it possible to incorporate other libraries - Great package management – crates.io - Open governance model - everyone can contribute to code High level abstraction – minimizes code, if you were to write a code to remove spaces Type inference - if you declare a variable as Unsigned 8 bit integer and you have pushed it to a vector which you didn’t define it will automatically give the vector unsigned 8bit integer datatype Reliability – rare to break – rust code is statically checked at compile time and also compile enforces the 2 concepts used in rust called ownership and borrowing. Interoperability with other languages using a Foreign Function Interface (FFI)
  19. - Simple main function
  20. Nightly – unstable features 6 weeks release cycle : only stable features A Request for Comments (RFC) is a formal document from the Internet Engineering Task Force ( IETF ) that is the result of committee drafting and subsequent review by interested parties. RFC becomes the standard and no further comments or changes are permitted.
  21. - I have referenced him since he is one python builder and currently building sentry - He created the python micro framework and most importantly he found rust efficient and useful in his work - He blended python and rust in an amazing way by also creating and contributing to the milksnake library
  22. Rust has great functionality which we don’t find in python – raw binary data If you needed to control of your machine and make most of your resource in the past you had one language C/ C++. Great power comes with great responsibility. Any small mistake can have catastrophic consequences or do the unexpected. The best scenario being a crash or worse open you to great security vulnerability. This is why systems programming has come to have horror of being a super hero. - Rust focuses on minimal core and extended by powerful libraries - Making it possible to incorporate other libraries - Great package management – crates.io - Open governance model - everyone can contribute to code High level abstraction – minimizes code, if you were to write a code to remove spaces Type inference - if you declare a variable as Unsigned 8 bit integer and you have pushed it to a vector which you didn’t define it will automatically give the vector unsigned 8bit integer datatype Reliability – rare to break – rust code is statically checked at compile time and also compile enforces the 2 concepts used in rust called ownership and borrowing.