SlideShare a Scribd company logo
1 of 28
Download to read offline
Lourens Naudé, Trade2Win


Inside Matz Ruby
High level Ruby internals crash
course.
Bio
   http://github.com/methodmissing
       Ruby contractor
       Currently building out a consumer forex platform @ Trade2Win.
   creator
       scrooge, mysqlplus_adapter, mri_instrumentation
   contributor
       Rails, mysqlplus, query_memcached, thinking-sphinx,
        em-spec
def users_of( :ruby )
 frequently()
 raise Opinion
rescue
 next_slide.call()
end
Have you looked at
   the source ?
Mere mortal, with a toolbox
   Basic C skills *
   Understanding of the UNIX subsystem *
   Dtrace *
   GDB *
   GCC macro expansion *
   Add preferred insomnia beverage
   * RTFM
The Symbol Table
   Generic hash implementation – bins && items
   Inits with 11 bins, > 5 items per bin spawns more
    for optimal density
   Table.has_many :bins
   Bin.has_maby :symbol_table_entries
   Strings or numbers as hash keys
   Global vars and classes stored in number table
   Collisions do happen … expensive
Values and identifiers
   VALUE and ID is an unsigned long
   Special types eg. true, false, nil directly
    represented by a VALUE … immediates
   The infamous nil with ID 4: #define Qnil 4
   struct RBasic {
       unsigned long flags;
       VALUE klass;
      };
Types
   One per builtin type : Array, Symbol etc.
   Special hidden types
       Mixed in modules
       Syntax tree nodes
       Variable scope
Casting Values
   Immediates ( nil ) looked up first for efficiency
   ROBJECT(123343434) → T_ARRAY
Type Flags
   Singleton class ?
   Marked for GC ?
   Tainted ?
   Any finalizers defined ?
   Instance variables defined on the object ?
   Frozen ?
Classes
 Instance variables + method table
 Super member
 Only for Kernel, class->super == NULL
 Array->super == Object
Objects
 Instance var table
 Object#method
       Searches the method table of it's class
       Fallback to superclass on 404
   Method cache busted when
       MyClass.send( :extend, OtherModule )
Method Inclusion
 class A
    include B
  end
 Included class : internal type for module
  mixins
 Pointer to the same ivar && method table
Hash
   Based on the symbol tables
       Iteration, insertion && removal
   Iteration level
       Track, and act upon, any changes during loops
   Mixed in modules
String
   Min. buffer size is 128 bytes
       's' occupies 128 – sizeof('s')
   static const char null_str[] = quot;quot;;
       New strings point to null_str for efficiency
   Locking mechanism
       String#gsub
       IO.read && IO#sysread buffers
Array
   Default capacity of 16 elements
       [x] occupies sizeof( 16 of x ) – sizeof(x)
   Locking mechanism
       Array#sort(!)
Preallocation
   Arrays and strings
       Similar structure : length && ptr members
 An initial and expandable capacity
 Slightly more space allocated to avoid
  reallocation overheads
 Supports sharing of values, where possible
Blocks
 Snapshots
 Optional arguments + a body
 Persistent local scope
 Linkable
       block->prev for iterators
Frames
   An item on the method call stack
   Arguments count and values
   Receiver state eg. AClass#method_invoked
   Links back to the previous frame
   Node state
Threads
 SIGVTALRM signal reserved
 Virtual ring through th->prev && th->next
 Evenly timesliced @ 10ms
 Threads can block for
       A single file descriptor
       A select operation
       Thread.join && Thread#value
Garbage Collection
   Process.has_many :heaps
       Where objects are stored
       Heap.has_many :slots


   Heap space maxed
       GC runs to free some space
       Allocates a new heap * 1.8 bigger
GC – Entries
   Entries
       Wraps core classes, nodes, scope etc.
   Reference values
       Flags + pointer to the next value
   Freelist is special global reference value
GC – Allocation and deallocation
   Object deallocation
       Immediates ignored
       Class frees method table, File close it's descriptor etc.
   New object allocation
       Force GC if no freelist
       Reference value assigned from the freelist
       Freelist updated to reflect the next free value
GC – Mark phase
   Object references it's klass, members etc.
       Module marks it's methods and ivar table
 Ignores immediates
 Each object recursively marks others
 Sets the marked flag for reference values
 Applicable to
       Global vars
       Variables currently on the stack
GC – Sweep phase
 Iterates through all objects
 Deletes objects not previously marked
 Defers sweeping if finalizer registered
Questions ?
Follow methodmissing @
github or twitter.Thanks!

More Related Content

What's hot

JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - OperatorsWebStackAcademy
 
Javascript session 01 - Introduction to Javascript
Javascript session 01 - Introduction to JavascriptJavascript session 01 - Introduction to Javascript
Javascript session 01 - Introduction to JavascriptLivingston Samuel
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchPedro Franceschi
 
Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsOWASP Kyiv
 
Learn Ajax here
Learn Ajax hereLearn Ajax here
Learn Ajax herejarnail
 
Squeak DBX
Squeak DBXSqueak DBX
Squeak DBXESUG
 
In Pursuit of the Grand Unified Template
In Pursuit of the Grand Unified TemplateIn Pursuit of the Grand Unified Template
In Pursuit of the Grand Unified Templatehannonhill
 
Jackson beyond JSON: XML, CSV
Jackson beyond JSON: XML, CSVJackson beyond JSON: XML, CSV
Jackson beyond JSON: XML, CSVTatu Saloranta
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101ygv2000
 
Scala for scripting
Scala for scriptingScala for scripting
Scala for scriptingmichid
 
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...DataStax
 
Simple Jackson with DropWizard
Simple Jackson with DropWizardSimple Jackson with DropWizard
Simple Jackson with DropWizardTatu Saloranta
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions WebStackAcademy
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingRadoslav Georgiev
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORPESUG
 
Cutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQueryCutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQueryWilliam Candillon
 

What's hot (20)

JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
 
Javascript session 01 - Introduction to Javascript
Javascript session 01 - Introduction to JavascriptJavascript session 01 - Introduction to Javascript
Javascript session 01 - Introduction to Javascript
 
Slickdemo
SlickdemoSlickdemo
Slickdemo
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearch
 
Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tips
 
Learn Ajax here
Learn Ajax hereLearn Ajax here
Learn Ajax here
 
Squeak DBX
Squeak DBXSqueak DBX
Squeak DBX
 
In Pursuit of the Grand Unified Template
In Pursuit of the Grand Unified TemplateIn Pursuit of the Grand Unified Template
In Pursuit of the Grand Unified Template
 
Jackson beyond JSON: XML, CSV
Jackson beyond JSON: XML, CSVJackson beyond JSON: XML, CSV
Jackson beyond JSON: XML, CSV
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
 
Scala for scripting
Scala for scriptingScala for scripting
Scala for scripting
 
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
CQL performance with Apache Cassandra 3.0 (Aaron Morton, The Last Pickle) | C...
 
Simple Jackson with DropWizard
Simple Jackson with DropWizardSimple Jackson with DropWizard
Simple Jackson with DropWizard
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft Training
 
Reversing JavaScript
Reversing JavaScriptReversing JavaScript
Reversing JavaScript
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORP
 
Lec 7
Lec 7Lec 7
Lec 7
 
Cutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQueryCutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQuery
 
Sql killedserver
Sql killedserverSql killedserver
Sql killedserver
 

Similar to Railswaycon Inside Matz Ruby

Cassandra Talk: Austin JUG
Cassandra Talk: Austin JUGCassandra Talk: Austin JUG
Cassandra Talk: Austin JUGStu Hood
 
On Rails with Apache Cassandra
On Rails with Apache CassandraOn Rails with Apache Cassandra
On Rails with Apache CassandraStu Hood
 
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016DataStax
 
Glorp Tutorial Guide
Glorp Tutorial GuideGlorp Tutorial Guide
Glorp Tutorial GuideESUG
 
Cassandra: Open Source Bigtable + Dynamo
Cassandra: Open Source Bigtable + DynamoCassandra: Open Source Bigtable + Dynamo
Cassandra: Open Source Bigtable + Dynamojbellis
 
Barcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentationBarcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentationSociable
 
JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...
JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...
JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...Maarten Balliauw
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHPRob Knight
 
mongodb-aggregation-may-2012
mongodb-aggregation-may-2012mongodb-aggregation-may-2012
mongodb-aggregation-may-2012Chris Westin
 
Java Script
Java ScriptJava Script
Java ScriptSarvan15
 
Java Script
Java ScriptJava Script
Java ScriptSarvan15
 
Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016takezoe
 

Similar to Railswaycon Inside Matz Ruby (20)

Cassandra Talk: Austin JUG
Cassandra Talk: Austin JUGCassandra Talk: Austin JUG
Cassandra Talk: Austin JUG
 
70 536
70 53670 536
70 536
 
On Rails with Apache Cassandra
On Rails with Apache CassandraOn Rails with Apache Cassandra
On Rails with Apache Cassandra
 
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
 
Glorp Tutorial Guide
Glorp Tutorial GuideGlorp Tutorial Guide
Glorp Tutorial Guide
 
Workin On The Rails Road
Workin On The Rails RoadWorkin On The Rails Road
Workin On The Rails Road
 
Qure Tech Presentation
Qure Tech PresentationQure Tech Presentation
Qure Tech Presentation
 
Cassandra: Open Source Bigtable + Dynamo
Cassandra: Open Source Bigtable + DynamoCassandra: Open Source Bigtable + Dynamo
Cassandra: Open Source Bigtable + Dynamo
 
Meta Object Protocols
Meta Object ProtocolsMeta Object Protocols
Meta Object Protocols
 
Barcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentationBarcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentation
 
JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...
JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...
JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHP
 
mongodb-aggregation-may-2012
mongodb-aggregation-may-2012mongodb-aggregation-may-2012
mongodb-aggregation-may-2012
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Java Script
Java ScriptJava Script
Java Script
 
Java Script
Java ScriptJava Script
Java Script
 
Lobos Introduction
Lobos IntroductionLobos Introduction
Lobos Introduction
 
Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016
 
Os Wilhelm
Os WilhelmOs Wilhelm
Os Wilhelm
 

More from Lourens Naudé

ZeroMQ as scriptable sockets
ZeroMQ as scriptable socketsZeroMQ as scriptable sockets
ZeroMQ as scriptable socketsLourens Naudé
 
TX/RX 101: Transfer data efficiently
TX/RX 101: Transfer data efficientlyTX/RX 101: Transfer data efficiently
TX/RX 101: Transfer data efficientlyLourens Naudé
 
In the Loop - Lone Star Ruby Conference
In the Loop - Lone Star Ruby ConferenceIn the Loop - Lone Star Ruby Conference
In the Loop - Lone Star Ruby ConferenceLourens Naudé
 
EuRuKo 2011 - In the Loop
EuRuKo 2011 - In the LoopEuRuKo 2011 - In the Loop
EuRuKo 2011 - In the LoopLourens Naudé
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven ArchitectureLourens Naudé
 
RailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMsRailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMsLourens Naudé
 
RailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your DomainRailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your DomainLourens Naudé
 

More from Lourens Naudé (9)

ZeroMQ as scriptable sockets
ZeroMQ as scriptable socketsZeroMQ as scriptable sockets
ZeroMQ as scriptable sockets
 
TX/RX 101: Transfer data efficiently
TX/RX 101: Transfer data efficientlyTX/RX 101: Transfer data efficiently
TX/RX 101: Transfer data efficiently
 
In the Loop - Lone Star Ruby Conference
In the Loop - Lone Star Ruby ConferenceIn the Loop - Lone Star Ruby Conference
In the Loop - Lone Star Ruby Conference
 
EuRuKo 2011 - In the Loop
EuRuKo 2011 - In the LoopEuRuKo 2011 - In the Loop
EuRuKo 2011 - In the Loop
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven Architecture
 
RailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMsRailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMs
 
RailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your DomainRailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your Domain
 
Barcamp PT
Barcamp PTBarcamp PT
Barcamp PT
 
Embracing Events
Embracing EventsEmbracing Events
Embracing Events
 

Recently uploaded

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

Railswaycon Inside Matz Ruby

  • 1. Lourens Naudé, Trade2Win Inside Matz Ruby High level Ruby internals crash course.
  • 2. Bio  http://github.com/methodmissing  Ruby contractor  Currently building out a consumer forex platform @ Trade2Win.  creator  scrooge, mysqlplus_adapter, mri_instrumentation  contributor  Rails, mysqlplus, query_memcached, thinking-sphinx, em-spec
  • 3.
  • 4. def users_of( :ruby ) frequently() raise Opinion rescue next_slide.call() end
  • 5. Have you looked at the source ?
  • 6. Mere mortal, with a toolbox  Basic C skills *  Understanding of the UNIX subsystem *  Dtrace *  GDB *  GCC macro expansion *  Add preferred insomnia beverage  * RTFM
  • 7. The Symbol Table  Generic hash implementation – bins && items  Inits with 11 bins, > 5 items per bin spawns more for optimal density  Table.has_many :bins  Bin.has_maby :symbol_table_entries  Strings or numbers as hash keys  Global vars and classes stored in number table  Collisions do happen … expensive
  • 8. Values and identifiers  VALUE and ID is an unsigned long  Special types eg. true, false, nil directly represented by a VALUE … immediates  The infamous nil with ID 4: #define Qnil 4  struct RBasic { unsigned long flags; VALUE klass; };
  • 9. Types  One per builtin type : Array, Symbol etc.  Special hidden types  Mixed in modules  Syntax tree nodes  Variable scope
  • 10. Casting Values  Immediates ( nil ) looked up first for efficiency  ROBJECT(123343434) → T_ARRAY
  • 11. Type Flags  Singleton class ?  Marked for GC ?  Tainted ?  Any finalizers defined ?  Instance variables defined on the object ?  Frozen ?
  • 12. Classes  Instance variables + method table  Super member  Only for Kernel, class->super == NULL  Array->super == Object
  • 13. Objects  Instance var table  Object#method  Searches the method table of it's class  Fallback to superclass on 404  Method cache busted when  MyClass.send( :extend, OtherModule )
  • 14. Method Inclusion  class A include B end  Included class : internal type for module mixins  Pointer to the same ivar && method table
  • 15. Hash  Based on the symbol tables  Iteration, insertion && removal  Iteration level  Track, and act upon, any changes during loops  Mixed in modules
  • 16. String  Min. buffer size is 128 bytes  's' occupies 128 – sizeof('s')  static const char null_str[] = quot;quot;;  New strings point to null_str for efficiency  Locking mechanism  String#gsub  IO.read && IO#sysread buffers
  • 17. Array  Default capacity of 16 elements  [x] occupies sizeof( 16 of x ) – sizeof(x)  Locking mechanism  Array#sort(!)
  • 18. Preallocation  Arrays and strings  Similar structure : length && ptr members  An initial and expandable capacity  Slightly more space allocated to avoid reallocation overheads  Supports sharing of values, where possible
  • 19. Blocks  Snapshots  Optional arguments + a body  Persistent local scope  Linkable  block->prev for iterators
  • 20. Frames  An item on the method call stack  Arguments count and values  Receiver state eg. AClass#method_invoked  Links back to the previous frame  Node state
  • 21. Threads  SIGVTALRM signal reserved  Virtual ring through th->prev && th->next  Evenly timesliced @ 10ms  Threads can block for  A single file descriptor  A select operation  Thread.join && Thread#value
  • 22. Garbage Collection  Process.has_many :heaps  Where objects are stored  Heap.has_many :slots   Heap space maxed  GC runs to free some space  Allocates a new heap * 1.8 bigger
  • 23. GC – Entries  Entries  Wraps core classes, nodes, scope etc.  Reference values  Flags + pointer to the next value  Freelist is special global reference value
  • 24. GC – Allocation and deallocation  Object deallocation  Immediates ignored  Class frees method table, File close it's descriptor etc.  New object allocation  Force GC if no freelist  Reference value assigned from the freelist  Freelist updated to reflect the next free value
  • 25. GC – Mark phase  Object references it's klass, members etc.  Module marks it's methods and ivar table  Ignores immediates  Each object recursively marks others  Sets the marked flag for reference values  Applicable to  Global vars  Variables currently on the stack
  • 26. GC – Sweep phase  Iterates through all objects  Deletes objects not previously marked  Defers sweeping if finalizer registered
  • 28. Follow methodmissing @ github or twitter.Thanks!