SlideShare a Scribd company logo
1 of 67
Download to read offline
1
Rust: Reach Further!
Nicholas Matsakis
2
Q. What is Rust?
Q. Why should I care?
3
Q. What is Rust?
Q. Why should I care?
A. High-level code, low-level performance
4
Decisions…
Double free?
Buffer overflow?
Dangling pointers?
Data races?
GC
😱
😱
😱
😱
😀
😀
😀
😱
😎
😎
😎
😎
Control, flexibility 😀 😕 😎
5
Static type system =
Eat your spinach!
Photo credit: Sanjoy Ghosh
https://www.flickr.com/photos/sanjoy/4016632253/
6
Photo credit: Salim Virji
https://www.flickr.com/photos/salim/8594532469/
Static type system = Eat your spinach!
7
The Rust compiler just saved me from a nasty threading bug. I was
working on cage (our open source development tool for Docker apps with
lots of microservices), and I decided to parallelize the routine that
transformed docker-compose.yml files.
8
Performance
class ::String
def blank?
/A[[:space:]]*z/ == self
end
end
Ruby:
964K iter/sec
static VALUE
rb_str_blank_as(VALUE str)
{
rb_encoding *enc;
char *s, *e;
enc = STR_ENC_GET(str);
s = RSTRING_PTR(str);
if (!s || RSTRING_LEN(str) == 0) return Qtrue;
e = RSTRING_END(str);
while (s < e) {
int n;
unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);
switch (cc) {
case 9:
case 0xa:
case 0xb:
case 0xc:
case 0xd:
case 0x20:
case 0x85:
case 0xa0:
case 0x1680:
case 0x2000:
case 0x2001:
case 0x2002:
case 0x2003:
case 0x2004:
case 0x2005:
case 0x2006:
case 0x2007:
case 0x2008:
case 0x2009:
case 0x200a:
case 0x2028:
case 0x2029:
case 0x202f:
case 0x205f:
case 0x3000:
#if ruby_version_before_2_2()
case 0x180e:
#endif
/* found */
break;
default:
return Qfalse;
}
s += n;
}
return Qtrue;
}
Performance
Ruby:
964K iter/sec
C:
10.5M iter/sec
10x!
https://github.com/SamSaffron/fast_blank
Performance
10
class ::String
def blank?
/A[[:space:]]*z/ == self
end
end
extern “C” fn fast_blank(buf: Buf) -> bool {
buf.as_slice().chars().all(|c| c.is_whitespace())
}
Get Rust
string slice
Get iterator over
each character
Are all characters
whitespace?
Rust:
11M iter/sec
Ruby:
964K iter/sec
C:
10.5M iter/sec
11
High-level, zero-cost abstractions
fn is_whitespace(text: &str) -> bool {
text.chars()
.all(|c| c.is_whitespace())
}
fn load_images(paths: &[PathBuf]) -> Vec<Image> {
paths.par_iter()
.map(|path| Image::load(path))
.collect()
}
12
Q. What is Rust?
Q. Why should I care?
A. You can do more!
A. High-level code, low-level performance
13
Experienced C++ hacker?
Prefer Ruby? JavaScript?
Make and maintain the designs you always
wanted — but could not justify.
Tune up your application and address hot-spots.
Lower memory usage. Add threads without fear.
14
I like Rust because it is boring.
— CJ Silverio, npm CTO
15
Design of Rust
Rust in Production
Rust Community
16
“Must be this
tall to write
multi-threaded
code”
David Baron

Mozilla Distinguished Engineer
Data races
Sharing
Mutation
No ordering
Data race
17
Actor-based languages
(e.g., Erlang, WebWorkers)
Functional languages
(e.g., Haskell)
Sequential programming
Data races
Sharing
Mutation
No ordering
Data race
18
Rust: No sharing and

mutation at the same time.
19
Ownership and BorrowingPhoto Credit: Nathan Kam
https://www.youtube.com/watch?v=Tnssn9KcWLg
Type Ownership Alias? Mutate?
T Owned ✓
~ Ownership and borrowing ~
fn main() {
let apple = Apple::new();
eat(apple);
}
21
fn eat(apple: Apple) {
…
}
Take ownership
of the apple
Give ownership
of the apple.
Owns
Owns
eat(apple);
~~~~~~~~~
Error: `apple` has
been moved.
fn main() {
let apple = Apple::new();
let mut bag = Vec::new();
bag.push(apple);
bag.push(Apple::new());
deliver(bag);
}
22
fn deliver(bag: Vec<Apple>) {
…
}
Take ownership
of the vector
Give ownership.
Give ownership.
Owns
Owns
23
“Manual” memory management in Rust:
Values owned by creator.
Values moved via assignment.
When final owner returns, value is freed.
Feels invisible.
]
~ Ownership and borrowing ~
Type Ownership
T
Alias? Mutate?
Owned ✓
&T Shared reference ✓
fn main() {
let apple = Apple::new();
let mut bag = Vec::new();
bag.push(apple);
bag.push(Apple::new());
let weight = weigh(&bag);
…
}
25
fn weigh(bag: &Vec<Apple>) -> u32 {
…
}
Shared reference
to the vector
Loan out the bag
(Return type)
shared
references
~~~~~~~~~
let mut bag = Vec::new();
bag.push(…);
let r = &bag;
bag.len();
bag.push(…);
r.push(…);
bag.push(…);
reading `bag` ok while shared
cannot mutate while shared
26
Sharing “freezes” data (temporarily)
`bag` mutable here
~~~~~~~~~~~
`bag` borrowed here
after last use of `r`, 

`bag` is mutable again
cannot mutate through shared ref
~ Ownership and borrowing ~
Type Ownership
T
&T
Alias? Mutate?
Owned
Shared reference
✓
✓
&mut T Mutable reference ✓
cannot access `bag` while borrowed
but can mutate through `r`
28
Mutable references: no other access
`bag` mutable here
~~~~~~~~~
`bag` mutably borrowed here
after last use of `r`, `bag` is
accessible again
let mut bag = Vec::new();
bag.push(…);
let r = &mut bag;
bag.len();
r.push(…);
bag.push(…);
29
Parallelism
Photo credit: Dave Gingrich
https://www.flickr.com/photos/ndanger/2744507570/
30
Observation:
Building parallel abstractions is easy.
Misusing those abstractions is also easy.
func foo(…) {
m := make(map[string]string)
m[“Hello”] = “World”
channel <- m
m[“Hello”] = “Data Race”
}
send data over channel
but how to stop sender from

using it afterwards?
GoCode
31
fn foo(…) {
let m = HashMap::new();
m.insert(“Hello”, “World”);
channel.send(m);
m.insert(“Hello”, “Data Race”);
}
impl<T> Channel<T> {
fn send(&mut self, data: T) {
…
}
}
Take ownership
of the data
Error: use of moved
value: `book`
~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Concurrency paradigms ~
Paradigm
Message passing
Ownership? Borrowing?
✓
Fork join ✓
33
fn load_images(paths: &[PathBuf]) -> Vec<Image> {
paths.iter()
.map(|path| {
Image::load(path)
})
.collect()
}
For each path…
…load an image…
…create and return
a vector.
paths = [ “a.jpg”, “b.png”, …, “c.jpg” ]
borrowed from caller
34
fn load_images(paths: &[PathBuf]) -> Vec<Image> {
paths.par_iter()
.map(|path| {
Image::load(path)
})
.collect()
}
Make it parallel
paths = [ “a.jpg”, “b.png”, …, “c.jpg” ]
extern crate rayon; Third-party library
35
Observation:
Building parallel abstractions is easy.
Misusing those abstractions is also easy.
36
fn load_images(paths: &[PathBuf]) -> Vec<Image> {
let mut jpgs = 0;
paths.par_iter()
.map(|path| {
if path.ends_with(“.jpg”) { jpgs += 1; }
Image::load(path)
})
.collect()
}
How many jpgs seen so far?
…add 1 to the counter.
If current file name ends in “jpg”…
0
0
+ 1
0
+ 1
1 1
1
fn load_images(paths: &[PathBuf]) -> Vec<Image> {
let mut jpgs = 0;
paths.par_iter()
.map( )
.collect()
}
37
borrows
mutably
borrows
mutably
|path| {
if path.ends_with(“.jpg”) {
jpgs += 1;
}
Image::load(path)
}
|path| {
if path.ends_with(“.jpg”) {
jpgs += 1;
}
Image::load(path)
}
~~~~~~~~~❌ ~~~~~~~~~❌
~ Concurrency paradigms ~
Paradigm
Message passing
Ownership? Borrowing?
✓
Fork join ✓
Lock-free
Futures
…
✓ ✓
✓ ✓
Locking ✓ ✓
39
Unsafe
40
Ownership and Borrowing
Parallelism
File
System
Referencecount
Rust: An Extensible Language
Core Language
Libraries
Safe abstractions
unsafe {
…
}
Ownership/borrowing/traits give tools to
enforce safe abstraction boundaries.
Trust me.
fn split_at_mut(…) {
}
Validates input, etc.
41
42
Stylo (Parallel CSS Rendering — coming in FF57)
Total KLOC Unsafe KLOC Unsafe %
Total 146.2 51.7 35%
Interesting stuff 71.6 1.4 1.9%
FFI Bindings 74.5 50.3 67.4%
43
Photo credit: Don Urban
https://www.flickr.com/photos/donpezzano/3044965125/
Integration
44
usehelix.com
Rubynode.js
neon-bindings/neon
PyO3/pyo3
dgrunwald/rust-cpython
CPython
getsentry/milksnake
45
ArrayBuffer
Worker
46
ArrayBuffer fn callback(mut vm: CallContext) {
let buffer = vm.arguments(0);
let guard: VmGuard = vm.lock();
let data = buffer.borrow_mut(&guard);
data
.par_iter_mut()
.for_each(|i| *i += 1);
}
vm
guard
borrows
data
buffer
data
47
ArrayBuffer
buffer
data
What could go wrong?
What if we invoked JS
callback while using `data`?
▶ Can’t: Invoking JS
callbacks requires mutable
borrow of `vm`!
vm
guard
borrow
data
48https://medium.com/@wireapp/3ff37fc98c3f
49
ruby! {
class Console {
def log(string: &str) {
println!("LOG: {:?}", string);
}
}
}
50
Rust in Production
51
Will discuss today!
Whitepapers
available online.
rust-lang.org/en-US/whitepapers.html
52
Category:
Experienced system devs
53
54
55
Photo credit: Salim Virji
https://www.flickr.com/photos/salim/8594532469/
Safety = Eat your spinach!
56
Gradual adoption
works.
57
Category:
Full-stack developers
58
"Because our product helps people identify why their
apps are slow, it is very important that we
ourselves do not make their app slow," says
Yehuda Katz, CTO of Tilde.
Performance monitoring software for RoR.
Written (initially) in Ruby, but hit performance limitations:
59
Why Rust?
Next, they prototyped the agent in C++. Although the
C++ implementation used fewer resources, it also
introduced an unacceptable risk of crashes.
Katz and his team spent time squeezing every drop
of performance out of Ruby including removing
uses of higher-level features of the language that
required more resources.
A. C++ without crashes means the whole
team can write performance critical code.
60
61
Community
Photo credit: David McSpadden
https://www.flickr.com/photos/familyclan/15535822737/
62
Focus: Productivity and Ergonomics
Culmination of 2017 roadmap efforts across the board:
documentation, language, tooling, libraries, etc.
63
RFC Process
64
Rust Teams
Core Team
Language Team
Library Team
Compiler Team
Dev Tools Team
Cargo Team
IDEs and Editor Team
Infrastructure Team
Release Team
Community Team
Documentation Team
Rustdoc Team
Moderation Team
Mostly open-source volunteers.
Mozilla employees are a small fraction.
65
Rust Domain Working Groups
Web Services
WebAssembly
CLI Apps
Embedded Devices
66
From http://jvns.ca/blog/2016/09/11/rustconf-keynote/
Open and welcoming
67
Want to learn more?
intorust.com
rust-lang.org
O’Reilly
(Screencasts)
Manning
No Starch
Armstrong
github.com/ctjhoa/rust-learning
Tons more at:

More Related Content

What's hot

Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02nikomatsakis
 
An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...Claudio Capobianco
 
The Rust Programming Language: an Overview
The Rust Programming Language: an OverviewThe Rust Programming Language: an Overview
The Rust Programming Language: an OverviewRoberto Casadei
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011Patrick Walton
 
Engineering fast indexes (Deepdive)
Engineering fast indexes (Deepdive)Engineering fast indexes (Deepdive)
Engineering fast indexes (Deepdive)Daniel Lemire
 
Rust Intro @ Roma Rust meetup
Rust Intro @ Roma Rust meetup Rust Intro @ Roma Rust meetup
Rust Intro @ Roma Rust meetup Claudio Capobianco
 
What the &~#@&lt;!? (Pointers in Rust)
What the &~#@&lt;!? (Pointers in Rust)What the &~#@&lt;!? (Pointers in Rust)
What the &~#@&lt;!? (Pointers in Rust)David Evans
 
To Swift 2...and Beyond!
To Swift 2...and Beyond!To Swift 2...and Beyond!
To Swift 2...and Beyond!Scott Gardner
 
Python Asíncrono - Async Python
Python Asíncrono - Async PythonPython Asíncrono - Async Python
Python Asíncrono - Async PythonJavier Abadía
 
Where destructors meet threads
Where destructors meet threadsWhere destructors meet threads
Where destructors meet threadsShuo Chen
 
Introduce to Rust-A Powerful System Language
Introduce to Rust-A Powerful System LanguageIntroduce to Rust-A Powerful System Language
Introduce to Rust-A Powerful System Language安齊 劉
 
sizeof(Object): how much memory objects take on JVMs and when this may matter
sizeof(Object): how much memory objects take on JVMs and when this may mattersizeof(Object): how much memory objects take on JVMs and when this may matter
sizeof(Object): how much memory objects take on JVMs and when this may matterDawid Weiss
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Charles Nutter
 
Clojure ♥ cassandra
Clojure ♥ cassandra Clojure ♥ cassandra
Clojure ♥ cassandra Max Penet
 
Engineering fast indexes
Engineering fast indexesEngineering fast indexes
Engineering fast indexesDaniel Lemire
 
Kernel-Level Programming: Entering Ring Naught
Kernel-Level Programming: Entering Ring NaughtKernel-Level Programming: Entering Ring Naught
Kernel-Level Programming: Entering Ring NaughtDavid Evans
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовYandex
 

What's hot (20)

Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
 
Introduction to Rust
Introduction to RustIntroduction to Rust
Introduction to Rust
 
An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...
 
The Rust Programming Language: an Overview
The Rust Programming Language: an OverviewThe Rust Programming Language: an Overview
The Rust Programming Language: an Overview
 
Why rust?
Why rust?Why rust?
Why rust?
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011
 
Rust言語紹介
Rust言語紹介Rust言語紹介
Rust言語紹介
 
Engineering fast indexes (Deepdive)
Engineering fast indexes (Deepdive)Engineering fast indexes (Deepdive)
Engineering fast indexes (Deepdive)
 
Rust Intro @ Roma Rust meetup
Rust Intro @ Roma Rust meetup Rust Intro @ Roma Rust meetup
Rust Intro @ Roma Rust meetup
 
What the &~#@&lt;!? (Pointers in Rust)
What the &~#@&lt;!? (Pointers in Rust)What the &~#@&lt;!? (Pointers in Rust)
What the &~#@&lt;!? (Pointers in Rust)
 
To Swift 2...and Beyond!
To Swift 2...and Beyond!To Swift 2...and Beyond!
To Swift 2...and Beyond!
 
Python Asíncrono - Async Python
Python Asíncrono - Async PythonPython Asíncrono - Async Python
Python Asíncrono - Async Python
 
Where destructors meet threads
Where destructors meet threadsWhere destructors meet threads
Where destructors meet threads
 
Introduce to Rust-A Powerful System Language
Introduce to Rust-A Powerful System LanguageIntroduce to Rust-A Powerful System Language
Introduce to Rust-A Powerful System Language
 
sizeof(Object): how much memory objects take on JVMs and when this may matter
sizeof(Object): how much memory objects take on JVMs and when this may mattersizeof(Object): how much memory objects take on JVMs and when this may matter
sizeof(Object): how much memory objects take on JVMs and when this may matter
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
 
Clojure ♥ cassandra
Clojure ♥ cassandra Clojure ♥ cassandra
Clojure ♥ cassandra
 
Engineering fast indexes
Engineering fast indexesEngineering fast indexes
Engineering fast indexes
 
Kernel-Level Programming: Entering Ring Naught
Kernel-Level Programming: Entering Ring NaughtKernel-Level Programming: Entering Ring Naught
Kernel-Level Programming: Entering Ring Naught
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
 

Similar to Rust: Reach Further (from QCon Sao Paolo 2018)

Node Interactive Debugging Node.js In Production
Node Interactive Debugging Node.js In ProductionNode Interactive Debugging Node.js In Production
Node Interactive Debugging Node.js In ProductionYunong Xiao
 
Rust: Reach Further
Rust: Reach FurtherRust: Reach Further
Rust: Reach Furthernikomatsakis
 
Debugging node in prod
Debugging node in prodDebugging node in prod
Debugging node in prodYunong Xiao
 
Who pulls the strings?
Who pulls the strings?Who pulls the strings?
Who pulls the strings?Ronny
 
Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvarsSam Marley-Jarrett
 
How Secure Are Docker Containers?
How Secure Are Docker Containers?How Secure Are Docker Containers?
How Secure Are Docker Containers?Ben Hall
 
Automatic and Interpretable Machine Learning with H2O and LIME
Automatic and Interpretable Machine Learning with H2O and LIMEAutomatic and Interpretable Machine Learning with H2O and LIME
Automatic and Interpretable Machine Learning with H2O and LIMEJo-fai Chow
 
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat Pôle Systematic Paris-Region
 
Filip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersFilip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersYury Chemerkin
 
Simplest-Ownage-Human-Observed… - Routers
 Simplest-Ownage-Human-Observed… - Routers Simplest-Ownage-Human-Observed… - Routers
Simplest-Ownage-Human-Observed… - RoutersLogicaltrust pl
 
Microarmy - by J2 Labs
Microarmy - by J2 LabsMicroarmy - by J2 Labs
Microarmy - by J2 LabsJames Dennis
 
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...DevSecCon
 
Jose Selvi - Side-Channels Uncovered [rootedvlc2018]
Jose Selvi - Side-Channels Uncovered [rootedvlc2018]Jose Selvi - Side-Channels Uncovered [rootedvlc2018]
Jose Selvi - Side-Channels Uncovered [rootedvlc2018]RootedCON
 
Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012Dan Kuebrich
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesHiroshi SHIBATA
 
Timelapse: interactive record/replay for the web
Timelapse: interactive record/replay for the webTimelapse: interactive record/replay for the web
Timelapse: interactive record/replay for the webbrrian
 
Performance Profiling in Rust
Performance Profiling in RustPerformance Profiling in Rust
Performance Profiling in RustInfluxData
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy PluginsPaul King
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Deepak Garg
 

Similar to Rust: Reach Further (from QCon Sao Paolo 2018) (20)

Node Interactive Debugging Node.js In Production
Node Interactive Debugging Node.js In ProductionNode Interactive Debugging Node.js In Production
Node Interactive Debugging Node.js In Production
 
Rust: Reach Further
Rust: Reach FurtherRust: Reach Further
Rust: Reach Further
 
Debugging node in prod
Debugging node in prodDebugging node in prod
Debugging node in prod
 
Who pulls the strings?
Who pulls the strings?Who pulls the strings?
Who pulls the strings?
 
Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvars
 
How Secure Are Docker Containers?
How Secure Are Docker Containers?How Secure Are Docker Containers?
How Secure Are Docker Containers?
 
Automatic and Interpretable Machine Learning with H2O and LIME
Automatic and Interpretable Machine Learning with H2O and LIMEAutomatic and Interpretable Machine Learning with H2O and LIME
Automatic and Interpretable Machine Learning with H2O and LIME
 
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
 
Filip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersFilip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routers
 
Simplest-Ownage-Human-Observed… - Routers
 Simplest-Ownage-Human-Observed… - Routers Simplest-Ownage-Human-Observed… - Routers
Simplest-Ownage-Human-Observed… - Routers
 
Microarmy - by J2 Labs
Microarmy - by J2 LabsMicroarmy - by J2 Labs
Microarmy - by J2 Labs
 
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
 
Techniques for Preserving Scientific Software Executions: Preserve the Mess o...
Techniques for Preserving Scientific Software Executions: Preserve the Mess o...Techniques for Preserving Scientific Software Executions: Preserve the Mess o...
Techniques for Preserving Scientific Software Executions: Preserve the Mess o...
 
Jose Selvi - Side-Channels Uncovered [rootedvlc2018]
Jose Selvi - Side-Channels Uncovered [rootedvlc2018]Jose Selvi - Side-Channels Uncovered [rootedvlc2018]
Jose Selvi - Side-Channels Uncovered [rootedvlc2018]
 
Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 Minutes
 
Timelapse: interactive record/replay for the web
Timelapse: interactive record/replay for the webTimelapse: interactive record/replay for the web
Timelapse: interactive record/replay for the web
 
Performance Profiling in Rust
Performance Profiling in RustPerformance Profiling in Rust
Performance Profiling in Rust
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012
 

Recently uploaded

Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...OnePlan Solutions
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfBrain Inventory
 
20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기Chiwon Song
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampVICTOR MAESTRE RAMIREZ
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?AmeliaSmith90
 
Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Neo4j
 
Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntelliSource Technologies
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024Mind IT Systems
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesShyamsundar Das
 
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example ProjectMastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example Projectwajrcs
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorShane Coughlan
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilVICTOR MAESTRE RAMIREZ
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesSoftwareMill
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLAlluxio, Inc.
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfTobias Schneck
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyRaymond Okyere-Forson
 
Kubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptxKubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptxPrakarsh -
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmonyelliciumsolutionspun
 

Recently uploaded (20)

Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdf
 
20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - Datacamp
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?
 
Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!
 
Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptx
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in Trivandrum
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security Challenges
 
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example ProjectMastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS Calculator
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-Council
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retries
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human Beauty
 
Kubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptxKubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptx
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
 

Rust: Reach Further (from QCon Sao Paolo 2018)

  • 2. 2 Q. What is Rust? Q. Why should I care?
  • 3. 3 Q. What is Rust? Q. Why should I care? A. High-level code, low-level performance
  • 4. 4 Decisions… Double free? Buffer overflow? Dangling pointers? Data races? GC 😱 😱 😱 😱 😀 😀 😀 😱 😎 😎 😎 😎 Control, flexibility 😀 😕 😎
  • 5. 5 Static type system = Eat your spinach! Photo credit: Sanjoy Ghosh https://www.flickr.com/photos/sanjoy/4016632253/
  • 6. 6 Photo credit: Salim Virji https://www.flickr.com/photos/salim/8594532469/ Static type system = Eat your spinach!
  • 7. 7 The Rust compiler just saved me from a nasty threading bug. I was working on cage (our open source development tool for Docker apps with lots of microservices), and I decided to parallelize the routine that transformed docker-compose.yml files.
  • 8. 8 Performance class ::String def blank? /A[[:space:]]*z/ == self end end Ruby: 964K iter/sec
  • 9. static VALUE rb_str_blank_as(VALUE str) { rb_encoding *enc; char *s, *e; enc = STR_ENC_GET(str); s = RSTRING_PTR(str); if (!s || RSTRING_LEN(str) == 0) return Qtrue; e = RSTRING_END(str); while (s < e) { int n; unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc); switch (cc) { case 9: case 0xa: case 0xb: case 0xc: case 0xd: case 0x20: case 0x85: case 0xa0: case 0x1680: case 0x2000: case 0x2001: case 0x2002: case 0x2003: case 0x2004: case 0x2005: case 0x2006: case 0x2007: case 0x2008: case 0x2009: case 0x200a: case 0x2028: case 0x2029: case 0x202f: case 0x205f: case 0x3000: #if ruby_version_before_2_2() case 0x180e: #endif /* found */ break; default: return Qfalse; } s += n; } return Qtrue; } Performance Ruby: 964K iter/sec C: 10.5M iter/sec 10x! https://github.com/SamSaffron/fast_blank
  • 10. Performance 10 class ::String def blank? /A[[:space:]]*z/ == self end end extern “C” fn fast_blank(buf: Buf) -> bool { buf.as_slice().chars().all(|c| c.is_whitespace()) } Get Rust string slice Get iterator over each character Are all characters whitespace? Rust: 11M iter/sec Ruby: 964K iter/sec C: 10.5M iter/sec
  • 11. 11 High-level, zero-cost abstractions fn is_whitespace(text: &str) -> bool { text.chars() .all(|c| c.is_whitespace()) } fn load_images(paths: &[PathBuf]) -> Vec<Image> { paths.par_iter() .map(|path| Image::load(path)) .collect() }
  • 12. 12 Q. What is Rust? Q. Why should I care? A. You can do more! A. High-level code, low-level performance
  • 13. 13 Experienced C++ hacker? Prefer Ruby? JavaScript? Make and maintain the designs you always wanted — but could not justify. Tune up your application and address hot-spots. Lower memory usage. Add threads without fear.
  • 14. 14 I like Rust because it is boring. — CJ Silverio, npm CTO
  • 15. 15 Design of Rust Rust in Production Rust Community
  • 16. 16 “Must be this tall to write multi-threaded code” David Baron
 Mozilla Distinguished Engineer
  • 17. Data races Sharing Mutation No ordering Data race 17 Actor-based languages (e.g., Erlang, WebWorkers) Functional languages (e.g., Haskell) Sequential programming
  • 18. Data races Sharing Mutation No ordering Data race 18 Rust: No sharing and
 mutation at the same time.
  • 19. 19 Ownership and BorrowingPhoto Credit: Nathan Kam https://www.youtube.com/watch?v=Tnssn9KcWLg
  • 20. Type Ownership Alias? Mutate? T Owned ✓ ~ Ownership and borrowing ~
  • 21. fn main() { let apple = Apple::new(); eat(apple); } 21 fn eat(apple: Apple) { … } Take ownership of the apple Give ownership of the apple. Owns Owns eat(apple); ~~~~~~~~~ Error: `apple` has been moved.
  • 22. fn main() { let apple = Apple::new(); let mut bag = Vec::new(); bag.push(apple); bag.push(Apple::new()); deliver(bag); } 22 fn deliver(bag: Vec<Apple>) { … } Take ownership of the vector Give ownership. Give ownership. Owns Owns
  • 23. 23 “Manual” memory management in Rust: Values owned by creator. Values moved via assignment. When final owner returns, value is freed. Feels invisible. ]
  • 24. ~ Ownership and borrowing ~ Type Ownership T Alias? Mutate? Owned ✓ &T Shared reference ✓
  • 25. fn main() { let apple = Apple::new(); let mut bag = Vec::new(); bag.push(apple); bag.push(Apple::new()); let weight = weigh(&bag); … } 25 fn weigh(bag: &Vec<Apple>) -> u32 { … } Shared reference to the vector Loan out the bag (Return type) shared references
  • 26. ~~~~~~~~~ let mut bag = Vec::new(); bag.push(…); let r = &bag; bag.len(); bag.push(…); r.push(…); bag.push(…); reading `bag` ok while shared cannot mutate while shared 26 Sharing “freezes” data (temporarily) `bag` mutable here ~~~~~~~~~~~ `bag` borrowed here after last use of `r`, 
 `bag` is mutable again cannot mutate through shared ref
  • 27. ~ Ownership and borrowing ~ Type Ownership T &T Alias? Mutate? Owned Shared reference ✓ ✓ &mut T Mutable reference ✓
  • 28. cannot access `bag` while borrowed but can mutate through `r` 28 Mutable references: no other access `bag` mutable here ~~~~~~~~~ `bag` mutably borrowed here after last use of `r`, `bag` is accessible again let mut bag = Vec::new(); bag.push(…); let r = &mut bag; bag.len(); r.push(…); bag.push(…);
  • 29. 29 Parallelism Photo credit: Dave Gingrich https://www.flickr.com/photos/ndanger/2744507570/
  • 30. 30 Observation: Building parallel abstractions is easy. Misusing those abstractions is also easy. func foo(…) { m := make(map[string]string) m[“Hello”] = “World” channel <- m m[“Hello”] = “Data Race” } send data over channel but how to stop sender from
 using it afterwards? GoCode
  • 31. 31 fn foo(…) { let m = HashMap::new(); m.insert(“Hello”, “World”); channel.send(m); m.insert(“Hello”, “Data Race”); } impl<T> Channel<T> { fn send(&mut self, data: T) { … } } Take ownership of the data Error: use of moved value: `book` ~~~~~~~~~~~~~~~~~~~~~~~~~~
  • 32. ~ Concurrency paradigms ~ Paradigm Message passing Ownership? Borrowing? ✓ Fork join ✓
  • 33. 33 fn load_images(paths: &[PathBuf]) -> Vec<Image> { paths.iter() .map(|path| { Image::load(path) }) .collect() } For each path… …load an image… …create and return a vector. paths = [ “a.jpg”, “b.png”, …, “c.jpg” ] borrowed from caller
  • 34. 34 fn load_images(paths: &[PathBuf]) -> Vec<Image> { paths.par_iter() .map(|path| { Image::load(path) }) .collect() } Make it parallel paths = [ “a.jpg”, “b.png”, …, “c.jpg” ] extern crate rayon; Third-party library
  • 35. 35 Observation: Building parallel abstractions is easy. Misusing those abstractions is also easy.
  • 36. 36 fn load_images(paths: &[PathBuf]) -> Vec<Image> { let mut jpgs = 0; paths.par_iter() .map(|path| { if path.ends_with(“.jpg”) { jpgs += 1; } Image::load(path) }) .collect() } How many jpgs seen so far? …add 1 to the counter. If current file name ends in “jpg”… 0 0 + 1 0 + 1 1 1 1
  • 37. fn load_images(paths: &[PathBuf]) -> Vec<Image> { let mut jpgs = 0; paths.par_iter() .map( ) .collect() } 37 borrows mutably borrows mutably |path| { if path.ends_with(“.jpg”) { jpgs += 1; } Image::load(path) } |path| { if path.ends_with(“.jpg”) { jpgs += 1; } Image::load(path) } ~~~~~~~~~❌ ~~~~~~~~~❌
  • 38. ~ Concurrency paradigms ~ Paradigm Message passing Ownership? Borrowing? ✓ Fork join ✓ Lock-free Futures … ✓ ✓ ✓ ✓ Locking ✓ ✓
  • 40. 40 Ownership and Borrowing Parallelism File System Referencecount Rust: An Extensible Language Core Language Libraries
  • 41. Safe abstractions unsafe { … } Ownership/borrowing/traits give tools to enforce safe abstraction boundaries. Trust me. fn split_at_mut(…) { } Validates input, etc. 41
  • 42. 42 Stylo (Parallel CSS Rendering — coming in FF57) Total KLOC Unsafe KLOC Unsafe % Total 146.2 51.7 35% Interesting stuff 71.6 1.4 1.9% FFI Bindings 74.5 50.3 67.4%
  • 43. 43 Photo credit: Don Urban https://www.flickr.com/photos/donpezzano/3044965125/ Integration
  • 46. 46 ArrayBuffer fn callback(mut vm: CallContext) { let buffer = vm.arguments(0); let guard: VmGuard = vm.lock(); let data = buffer.borrow_mut(&guard); data .par_iter_mut() .for_each(|i| *i += 1); } vm guard borrows data buffer data
  • 47. 47 ArrayBuffer buffer data What could go wrong? What if we invoked JS callback while using `data`? ▶ Can’t: Invoking JS callbacks requires mutable borrow of `vm`! vm guard borrow data
  • 49. 49 ruby! { class Console { def log(string: &str) { println!("LOG: {:?}", string); } } }
  • 51. 51 Will discuss today! Whitepapers available online. rust-lang.org/en-US/whitepapers.html
  • 53. 53
  • 54. 54
  • 55. 55 Photo credit: Salim Virji https://www.flickr.com/photos/salim/8594532469/ Safety = Eat your spinach!
  • 58. 58 "Because our product helps people identify why their apps are slow, it is very important that we ourselves do not make their app slow," says Yehuda Katz, CTO of Tilde. Performance monitoring software for RoR. Written (initially) in Ruby, but hit performance limitations:
  • 59. 59 Why Rust? Next, they prototyped the agent in C++. Although the C++ implementation used fewer resources, it also introduced an unacceptable risk of crashes. Katz and his team spent time squeezing every drop of performance out of Ruby including removing uses of higher-level features of the language that required more resources. A. C++ without crashes means the whole team can write performance critical code.
  • 60. 60
  • 61. 61 Community Photo credit: David McSpadden https://www.flickr.com/photos/familyclan/15535822737/
  • 62. 62 Focus: Productivity and Ergonomics Culmination of 2017 roadmap efforts across the board: documentation, language, tooling, libraries, etc.
  • 64. 64 Rust Teams Core Team Language Team Library Team Compiler Team Dev Tools Team Cargo Team IDEs and Editor Team Infrastructure Team Release Team Community Team Documentation Team Rustdoc Team Moderation Team Mostly open-source volunteers. Mozilla employees are a small fraction.
  • 65. 65 Rust Domain Working Groups Web Services WebAssembly CLI Apps Embedded Devices
  • 67. 67 Want to learn more? intorust.com rust-lang.org O’Reilly (Screencasts) Manning No Starch Armstrong github.com/ctjhoa/rust-learning Tons more at: