SlideShare une entreprise Scribd logo
1  sur  65
Télécharger pour lire hors ligne
RubyMotion:
Under the Hood
Inspired by Click and Clack

Monday, October 14, 2013
A brief introduction

Monday, October 14, 2013
About Me

Name: Joshua Ballanco
Monday, October 14, 2013
About Me

Employer: Burnside Digital
Monday, October 14, 2013
About Me

Location: Ankara, Turkey
Monday, October 14, 2013
A slightly longer
introduction

Monday, October 14, 2013
Before...

Monday, October 14, 2013
About Me

Employer: Patch
Monday, October 14, 2013
About Me

Location: New York City
Monday, October 14, 2013
Before that...

Monday, October 14, 2013
About Me

Employer: Apple
Monday, October 14, 2013
About Me

Location: Cupertino
Monday, October 14, 2013
Before that...

Monday, October 14, 2013
About Me

School: University of Miami
Monday, October 14, 2013
About Me

Location: Miami
Monday, October 14, 2013
A bit of history

Monday, October 14, 2013
In graduate school

Monday, October 14, 2013
In graduate school

Monday, October 14, 2013
At Apple... Retail

Monday, October 14, 2013
At Apple

Laurent Sansonetti

Monday, October 14, 2013
After Apple...

Monday, October 14, 2013
Episode VI - The Return
of The RubyMotion

Monday, October 14, 2013
What is RubyMotion?
• Use Ruby to build apps for iOS and OS X
• Native apps
• Interface directly with Obj-C libraries
• CLI-based build system

Monday, October 14, 2013
What is RubyMotion?
• RubyMotion: http://www.rubymotion.com/
• MotionCasts: http://motioncasts.tv/
• RubyMotion Wrappers:
!

http://rubymotion-wrappers.com/

• ...and lot’s more

Monday, October 14, 2013
What is MacRuby?
• Intended to be the implementation of Ruby
2.0 for OS X

• Target RubySpec compliance
• JIT or AOT Compiled
• Uses libauto for Garbage Collection

Monday, October 14, 2013
What is MacRuby?
Ruby Syntax

Parser

Compiler

VM (sans GVL)

LLVM (with JIT)

Objective-C Runtime

Monday, October 14, 2013
Running a “something.rb” file
Ruby Syntax

Parser

Compiler

VM (sans GVL)

LLVM (with JIT)

Objective-C Runtime

Monday, October 14, 2013
Running a “something.rb” file
Ruby Syntax

Parser

Compiler

VM (sans GVL)

LLVM (with JIT)

Objective-C Runtime

Monday, October 14, 2013
Running a “something.rb” file
Ruby Syntax

Parser

Compiler

VM (sans GVL)

LLVM (with JIT)

Objective-C Runtime

Monday, October 14, 2013
AOT compiling “something.rb”
Ruby Syntax

Parser

Compiler

VM (sans GVL)

Objective-C Runtime

Monday, October 14, 2013

LLVM

something.o
AOT compiling “something.rb”
Ruby Syntax

Parser

Compiler

VM (sans GVL)

Objective-C Runtime

Monday, October 14, 2013

LLVM

something.o
Running an AOT compiled
“something.rb”
Parser

Compiler

VM (sans GVL)

Objective-C Runtime

Monday, October 14, 2013

something.o
Running an AOT compiled
“something.rb”
Parser

Compiler

VM (sans GVL)

Objective-C Runtime

Monday, October 14, 2013

something.o
Running an AOT compiled
“something.rb”
Parser

Compiler
LLVM
VM (sans GVL)

Objective-C Runtime

Monday, October 14, 2013

something.o
Running an AOT compiled
“something.rb”
Parser

Compiler
LLVM
VM (sans GVL)

Objective-C Runtime

Monday, October 14, 2013

something.o
Running an AOT compiled
“something.rb”
Parser

Compiler
LLVM
VM (sans GVL)

Objective-C Runtime

Monday, October 14, 2013

something.o
What is RubyMotion?
• Descendent of MacRuby
• “Ruby, the Good Parts”
• Static Compiled
• Retain/release reference counting

Monday, October 14, 2013
Static compiling “something.rb”
Ruby Syntax

Parser

Compiler

VM (sans GVL)

Objective-C Runtime

Monday, October 14, 2013

LLVM

something.o
Static compiling “something.rb”
Ruby Syntax

Parser

Compiler

VM (sans GVL)

Objective-C Runtime

Monday, October 14, 2013

LLVM

something.o
Running a static compiled
“something.rb”
VM (sans GVL)

Objective-C Runtime

Monday, October 14, 2013

something.o
Running a static compiled
“something.rb”
VM (sans GVL)

Objective-C Runtime

Monday, October 14, 2013

something.o
Why must we statically
compile?
• On OS X
• Compile writes code to a memory
page

• Runtime runs the code from that
memory page

Monday, October 14, 2013
Why must we statically
compile?
•

On iOS
Memory pages must be writable or
executable, NOT BOTH!

•
•
•

Monday, October 14, 2013

•

OS prohibits runtime compilation
Apple prohibits interpreting arbitrary scripts
...but you wouldn’t want an interpreter
anyway
Garbage Collection

Monday, October 14, 2013
What happened to the
Garbage Collector?
It required extra threads, so we
had to kill it...

Monday, October 14, 2013
So RubyMotion Uses
ARC?
Yes...
Uh...no
...sorta?

Monday, October 14, 2013
ARC vs “ARC”
• Objective-C’s ARC modifies your code
before compilation

• RubyMotion VM knows when retain and/or
release should be called...your code is not
touched

Monday, October 14, 2013
ARC vs “ARC”
Isn’t the distinction
rather academic?
Probably...

Monday, October 14, 2013
“ARC” Caveats
• Collection happens when the autorelease
pool drains

• Need to be careful with tight loops that
generate many objects

• Use “autorelease do...end”

• Detects almost all cycles
• Use WeakRefs if cycles become
problematic

Monday, October 14, 2013
Debugging RubyMotion
• Remember, RubyMotion objects are
Objective-C objects...

• All the usual tricks are valid!

Monday, October 14, 2013
Let’s Play!

Monday, October 14, 2013
The Victim
app/app_delegate.rb

Monday, October 14, 2013
The Victim
app/app_delegate.rb

Monday, October 14, 2013
REPL Magic

Monday, October 14, 2013
REPL Magic

Monday, October 14, 2013
REPL Magic

Monday, October 14, 2013
REPL Magic

Monday, October 14, 2013
That’s cool...but can
you do it in a
debugger???

Monday, October 14, 2013
Debugger Wizardry

Monday, October 14, 2013
Debugger Wizardry

Monday, October 14, 2013
Debugger Wizardry

Monday, October 14, 2013
Debugger Wizardry

Monday, October 14, 2013
That’s CRAZY!
I know...but it’s fun!

Monday, October 14, 2013
Debugging RubyMotion
• Helper methods “pro” and “pri”
• http://www.rubymotion.com/developercenter/articles/debugging/

• Watch for more/better tooling to come...

Monday, October 14, 2013
Questions?
Joshua Ballanco
@manhattanmetric
https://github.com/jballanc

Monday, October 14, 2013

Contenu connexe

En vedette (6)

Getting Your Ruby EGOT
Getting Your Ruby EGOTGetting Your Ruby EGOT
Getting Your Ruby EGOT
 
MacRuby for Fun and Profit
MacRuby for Fun and ProfitMacRuby for Fun and Profit
MacRuby for Fun and Profit
 
A Tale of Two Rubies
A Tale of Two RubiesA Tale of Two Rubies
A Tale of Two Rubies
 
MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?
 
There and Back Again
There and Back AgainThere and Back Again
There and Back Again
 
Ruby memory model
Ruby memory modelRuby memory model
Ruby memory model
 

Similaire à RubyMotion: Under the Hood

Similaire à RubyMotion: Under the Hood (20)

Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013
Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013
Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013
 
Microservices and functional programming
Microservices and functional programmingMicroservices and functional programming
Microservices and functional programming
 
Recommender Systems with Ruby (adding machine learning, statistics, etc)
Recommender Systems with Ruby (adding machine learning, statistics, etc)Recommender Systems with Ruby (adding machine learning, statistics, etc)
Recommender Systems with Ruby (adding machine learning, statistics, etc)
 
Ruby off Rails
Ruby off RailsRuby off Rails
Ruby off Rails
 
Contributing to WordPress
Contributing to WordPressContributing to WordPress
Contributing to WordPress
 
Enterprise rails hosting 3 ways to scale - 2011-10
Enterprise rails hosting   3 ways to scale - 2011-10 Enterprise rails hosting   3 ways to scale - 2011-10
Enterprise rails hosting 3 ways to scale - 2011-10
 
Smartgears
SmartgearsSmartgears
Smartgears
 
Latinoware Rails 2009
Latinoware Rails 2009Latinoware Rails 2009
Latinoware Rails 2009
 
Cartoset
CartosetCartoset
Cartoset
 
Merged Automation Talk - Pete Carapetyan - Feb 2016
Merged Automation Talk - Pete Carapetyan - Feb 2016 Merged Automation Talk - Pete Carapetyan - Feb 2016
Merged Automation Talk - Pete Carapetyan - Feb 2016
 
Making WordPress Fly
Making WordPress FlyMaking WordPress Fly
Making WordPress Fly
 
Slaying Bugs with Gradle and Jenkins
Slaying Bugs with Gradle and JenkinsSlaying Bugs with Gradle and Jenkins
Slaying Bugs with Gradle and Jenkins
 
Cooking an Omelette with Chef
Cooking an Omelette with ChefCooking an Omelette with Chef
Cooking an Omelette with Chef
 
Mastering ElasticSearch with Ruby and Tire
Mastering ElasticSearch with Ruby and TireMastering ElasticSearch with Ruby and Tire
Mastering ElasticSearch with Ruby and Tire
 
Essential Test-Driven Development
Essential Test-Driven DevelopmentEssential Test-Driven Development
Essential Test-Driven Development
 
Application Architectures in Grails
Application Architectures in GrailsApplication Architectures in Grails
Application Architectures in Grails
 
RubyMotion: Put your Dreams in Motion with Ruby
RubyMotion: Put your Dreams in Motion with RubyRubyMotion: Put your Dreams in Motion with Ruby
RubyMotion: Put your Dreams in Motion with Ruby
 
Angular from Scratch
Angular from ScratchAngular from Scratch
Angular from Scratch
 
Ruby meetup 7_years_in_testing
Ruby meetup 7_years_in_testingRuby meetup 7_years_in_testing
Ruby meetup 7_years_in_testing
 
Learning Rust By Building Small CLI Tools!.pdf
Learning Rust By Building Small CLI Tools!.pdfLearning Rust By Building Small CLI Tools!.pdf
Learning Rust By Building Small CLI Tools!.pdf
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

RubyMotion: Under the Hood