SlideShare a Scribd company logo
Dynamic Language VMs Ruby 1.9 Lourens Naude, WildfireApp.com
Background Independent Contractor Ruby / C / integrations
Well versed full stack
Architecture WildfireApp.com Social Marketing platform
Large whitelabel clients
Bursty traffic – Lady Gaga, EA, Gatorade etc.
 
RUBY VM INTERNALS ?
A GOOD CRAFTSMEN KNOWS HIS TOOLS
A BAD CRAFTSMEN BLAMES HIS TOOLS
Typical public facing apps Interaction patterns Request / response
Time
Event driven Overheads Data transfer (I/0)
Serialization / coercion (CPU)
VM – allocation, symbol tables etc. (CPU + mem)
Business requirements (CPU)
Ruby daemon - strace Process 5856 detached % time  calls  syscall ------  ------- ------------- 89.69  5092  recvfrom 5.35  5093  sendto 2.49  26300  stat 2.05  11004  clock_gettime
Ruby daemon - ltrace % time  calls  function ------  -------- -------- 95.78  635173  memcpy 1.38  25862  malloc 0.79  14984  free 0.60  11403  strcmp
System Resources Data latency CPU cache
Memory – local
Disk - local
Memory + disk - remote Record retrieval with ORM Fetch results (local/remote memory + disk)
Serialization + conversion (CPU)
Object instantiation (CPU + memory)
Optional memcached (local or remote memory)
RUBY ?
Conversion – rows to hash Benchmark.bm do |b| b.report do 1000.times{ ActiveRecord::Base.connection.select_rows "SELECT * FROM users" } end end user  system  total  real 0.300000  0.040000  0.340000 (  0.505095)
Conversion – rows to objects Benchmark.bm do |b| b.report do 1000.times{ ActiveRecord::Base.connection.select_all "SELECT * FROM users" } end end user  system  total  real 0.510000  0.050000  0.560000 (  0.719201)
Instantiation Benchmark.bm do |b| b.report do 100_000.times{ 'string'.dup } end end user  system  total  real 0.040000  0.000000  0.040000 (  0.043791)
Serialization – load + dump Benchmark.bm do |b| b.report do 100_000.times{ Marshal.load(Marshal.dump('ruby string')) } end end user  system  total  real 1.660000  0.010000  1.670000 (  1.699882)
Roadmap VM Architecture Symbol table
Opcodes / instructions
Dispatch
Optimizations Ruby language Object model
Garbage Collection
Contexts and control flow
Concurrency
VM ARCHITECTURE
 
Changes Ruby 1.8 artifacts Parser && AST nodes
Object model
Garbage Collection
No immediate performance gains for String manipulation etc. Codegen phase Better optimization hooks
Faster runtime
AST AND CODEGEN
 
Abstract Syntax Tree (AST) Structure Grammar representation
Annotations attach semantics to nodes
Possible to refactor the tree – more nodes, less complexity Example nodes Literals, values and assignments
Method calls, arguments and return values
Jumps – if, else, iterators
Unconditional jumps – exceptions, retry etc.
Code generation How it works Converts the AST to compiled code segments
Reduces a tree to a linear and ordered instruction set
Fast execution – no tree walking + native code Workflow Preprocessing – AST refactoring (!YARV)
Codegen, nodes -> instruction sequences
Postprocessing – replace with optimal instruction sequences (peephole optimization)
Pre and postprocessing phases may be multiple passes
LOOKUPS
 
Symbol / Hash tables How it works Constant time access to int/char indexed values
Table defaults: 11 bins, 5 entries per bin
Bins++, sequential lookup inside bins
Lookup of methods, variables, encodings etc. Symbol Entity with both a String and Number representation
!(String || Symbol), points to a table entry
Developer identifies by name, VM by int
Immutable for performance – watch out for memory
VM INSTRUCTIONS
VM instructions / opcodes Stateless functions 80+ currently
Generated from definitions at interpreter compile time (existing ruby requirement for 1.9)
Instruction / opcode / operands notation Categories and examples variable: get or set local variable
class / module: definition
method / iterator: invoke method, call block
Optimization: redefines common +, <<, * contracts
Managing opcode sequences Stack Machine 2 instruction types: push && pop
Move / copy values, top of stack -> elsewhere
SP: top of stack pointer, BP: bottom of stack pointer Example %w(a b c)
Put strings “a”, “b” and “c” on the stack
Fetch top 3 stack elements
Create an array from them
Instruction sequence Opcode collection Instruction dispatch can be a bottleneck
Optimizing simple instructions is very important
Likely a small subset of the typical web app's hot path Dispatch techniques Direct Threaded Dispatch : fastest jump to next opcode / instruction
Switch Dispatch : slower, but portable
DISPATCH AND CACHE
Dispatch techniques Direct Threaded Dispatch Represents an instruction by the address of the routine that implements it
Forth, Python 3
Not portable: GCC first class labels Switch Dispatch CPU branch mispredictions, depending on pipeline length
Up to 50% slower than Threaded dispatch
Portable
VM Caches Versioning State counter scopes caches to the current VM state
Lazy invalidation – just bump the version Expires on constant definition
constant removal
method definition
method removal
method cache changes (covered later)
OPTIMIZATIONS
Optimization Limitations Static Analysis Examine source code without execution

More Related Content

PDF
Compiler Construction | Lecture 13 | Code Generation
PDF
How to check valid Email? Find using regex.
PPT
Assembler (2)
PPT
Assembler
PPTX
07 140430-ipp-languages used in llvm during compilation
PDF
PPT
Assembler
PPT
Assembler
Compiler Construction | Lecture 13 | Code Generation
How to check valid Email? Find using regex.
Assembler (2)
Assembler
07 140430-ipp-languages used in llvm during compilation
Assembler
Assembler

What's hot (20)

PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
PPTX
[ASM]Lab4
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
PDF
Alp 05
PPTX
C programming language tutorial
PPT
Introduction to c programming
PPT
Assembler design options
PPT
Assembler design option
DOC
'C' language notes (a.p)
PPTX
C Programming Language Step by Step Part 1
PPTX
[ASM]Lab6
PPTX
C LANGUAGE - BESTECH SOLUTIONS
PDF
C programming session8
PPT
Assembly Language Lecture 5
PDF
C programming session10
PPTX
C Programming Language Tutorial for beginners - JavaTpoint
PPTX
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
PDF
Unit 4 assembly language programming
PDF
Introduction to R
PDF
Assembly language 8086
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
[ASM]Lab4
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Alp 05
C programming language tutorial
Introduction to c programming
Assembler design options
Assembler design option
'C' language notes (a.p)
C Programming Language Step by Step Part 1
[ASM]Lab6
C LANGUAGE - BESTECH SOLUTIONS
C programming session8
Assembly Language Lecture 5
C programming session10
C Programming Language Tutorial for beginners - JavaTpoint
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Unit 4 assembly language programming
Introduction to R
Assembly language 8086
Ad

Viewers also liked (6)

PPT
PDF
実践リーダブルコード - 課題の実装の進め方
PDF
Eterotopie Manageriali
PPT
Publicidad Julio
PPT
Hermandad de la Plaza
PPT
Php Ppt
実践リーダブルコード - 課題の実装の進め方
Eterotopie Manageriali
Publicidad Julio
Hermandad de la Plaza
Php Ppt
Ad

Similar to RailswayCon 2010 - Dynamic Language VMs (20)

PDF
How it's made: C++ compilers (GCC)
PPT
Clojure concurrency
ODP
Domain Specific Languages In Scala Duse3
PDF
Scheme on WebAssembly: It is happening!
PPT
NOSQL and Cassandra
PPTX
Introduction to c_plus_plus (6)
PPTX
Introduction to c_plus_plus
PDF
What C and C++ Can Do and When Do You Need Assembly? by Alexander Krizhanovsky
ODP
Ast transformation
PDF
Otimizando Aplicações em Rails
PPTX
tau 2015 spyrou fpga timing
PDF
Compiler Construction | Lecture 12 | Virtual Machines
PPTX
The Style of C++ 11
PPT
Chapter Seven(2)
PDF
New features in Ruby 2.5
PDF
Building a High-Performance Database with Scala, Akka, and Spark
PPTX
Advanced procedures in assembly language Full chapter ppt
PDF
Cassandra 2.1 boot camp, Overview
PDF
Profiling Ruby
PPTX
Summary of C++17 features
How it's made: C++ compilers (GCC)
Clojure concurrency
Domain Specific Languages In Scala Duse3
Scheme on WebAssembly: It is happening!
NOSQL and Cassandra
Introduction to c_plus_plus (6)
Introduction to c_plus_plus
What C and C++ Can Do and When Do You Need Assembly? by Alexander Krizhanovsky
Ast transformation
Otimizando Aplicações em Rails
tau 2015 spyrou fpga timing
Compiler Construction | Lecture 12 | Virtual Machines
The Style of C++ 11
Chapter Seven(2)
New features in Ruby 2.5
Building a High-Performance Database with Scala, Akka, and Spark
Advanced procedures in assembly language Full chapter ppt
Cassandra 2.1 boot camp, Overview
Profiling Ruby
Summary of C++17 features

More from Lourens Naudé (9)

PDF
ZeroMQ as scriptable sockets
PDF
TX/RX 101: Transfer data efficiently
PDF
In the Loop - Lone Star Ruby Conference
PDF
EuRuKo 2011 - In the Loop
PDF
Event Driven Architecture
ODP
RailswayCon 2010 - Command Your Domain
PDF
Barcamp PT
PDF
Railswaycon Inside Matz Ruby
PDF
Embracing Events
ZeroMQ as scriptable sockets
TX/RX 101: Transfer data efficiently
In the Loop - Lone Star Ruby Conference
EuRuKo 2011 - In the Loop
Event Driven Architecture
RailswayCon 2010 - Command Your Domain
Barcamp PT
Railswaycon Inside Matz Ruby
Embracing Events

Recently uploaded (20)

PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
Teaching material agriculture food technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
A Presentation on Artificial Intelligence
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Teaching material agriculture food technology
20250228 LYD VKU AI Blended-Learning.pptx
Approach and Philosophy of On baking technology
SOPHOS-XG Firewall Administrator PPT.pptx
Programs and apps: productivity, graphics, security and other tools
MIND Revenue Release Quarter 2 2025 Press Release
Digital-Transformation-Roadmap-for-Companies.pptx
Electronic commerce courselecture one. Pdf
A comparative analysis of optical character recognition models for extracting...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
A Presentation on Artificial Intelligence
Building Integrated photovoltaic BIPV_UPV.pdf
Empathic Computing: Creating Shared Understanding
Assigned Numbers - 2025 - Bluetooth® Document
Agricultural_Statistics_at_a_Glance_2022_0.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
MYSQL Presentation for SQL database connectivity
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

RailswayCon 2010 - Dynamic Language VMs