SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
Ruby 2.4 Internals
Koichi Sasada
ko1@cookpad.com
Note:
Ruby 2.4.0 has
several bugs.
Note2:
No x.y.0 doesn’t
have several bugs.
Ruby 2.4.0
New features
written in a release announcement
• Introduce hash table improvement (by Vladimir Makarov)
• Binding#irb: Start a REPL session similar to binding.pry
• Unify Fixnum and Bignum into Integer
• String supports Unicode case mappings
• Performance improvements
• Array#max, Array#min
• Regexp#match?
• speed up instance variable access
• Debugging
• Thread#report_on_exception and Thread.report_on_exception
• Thread deadlock detection now shows threads with their backtrace and dependency
• Other notable changes since 2.3
• Support OpenSSL 1.1.0 (drop support for 0.9.7 or prior)
• ext/tk is now removed from stdlib Feature #8539
• XMLRPC is now removed from stdlib Feature #12160
Ruby 2.4 Internals
Koichi Sasada
ko1@cookpad.com
https://blog.heroku.com/r
uby-2-4-features-hashes-
integers-rounding
Any other
topics?
benchmark/bm_app_lc_fizzbuzz.rb
Bug #10212 MRI is not for lambda calculus
JRuby 26 sec
mruby 27 sec
MRI 114 sec
Feature #12628
change block/env structs
Ruby 2.4 Internals
Change block/env structs
Koichi Sasada
ko1@cookpad.com
Issues
1. we need to clear
rb_control_frame_t::block_iseq for
every frame setup. It consumes space (a
VALUE for each frame) and initializing
time.
2. There are several block passing ways by
ISeq (iter{...}), Proc(iter(&pr)),
Symbol(iter(:sym)). However, they are
not optimized (for Symbol blocks, there
is only ad-hoc check code).
3. Env (and Proc, Binding) objects are not
WB-protected ([Bug #10212]).
Method dispatch (etc)
improvements
Cleanup src code
Improve GC perf.
Patch
•https://github.com/ruby/ruby/compare/tru
nk...ko1:block_code
•“Showing with 1,863 additions and 1,070
deletions.”
Approaches
•For (1), (2)
•Introduce Block Handler (BH)
•Using BH
•For (3)
•Introduce Write Barriers (WB) for Env objects
WB protected or unprotected?
•Ruby 2.1.0 introduced Generational GC
•Only newer objects
•GenGC requires “Write barriers” (WB), but
MRI allows WB unprotected objects
(See my past presentations for details)
•WB protected objects: GenGC → Fast
•WB unprotected objects: Not GenGC → Slow
RubyVM::Env objects
•Env objects represent
captured local variables
•Each Proc or Binding has
at least one Env object
•Proc object “$pr”
consists of 3 Env objects
a = 1
1.times{|b|
1.times{|c|
$pr = Proc.new{
# you can access a, b, c
}
}
}
Proc
$pr
Env
c=0
Env
b=0
Env
a=1
RubyVM::Env objects were
WB-unprotected
•They were WB unprotected because:
•Difficulty of implementation
•Performance issue
Performance issue
Assignment performance
• Ruby 2.3 or before
*(ep - idx) = val;
• Naïve implementation
#define VM_EP_IN_HEAP_P(th, ep) ÂĽ
(!((th)->stack <= (ep) && ÂĽ
(ep) < ((th)->stack + (th)->stack_size)))
if (VM_EP_IN_HEAP_P(ep)) {
RB_OBJ_WRITE(VM_ENV_EP_ENVVAL(ep),
ep-idx, val);
}
else *(ep - idx) = val;
Ideas
1. Lightweight escape detection
2. Skip WB except really required timing
Idea
Lightweight escape detection
•Move cfp->flags to ep[0]
•Introduce a VM_ENV_FLAG_ESCAPED flag to
represent escaped Env.
• // Before
#define VM_EP_IN_HEAP_P(th, ep) (!((th)->stack <= (ep) && (ep) < ((th)->stack + (th)->stack_size)))
• // After
#define VM_EP_IN_HEAP_P(ep) (ep[0] & VM_ENV_FLAG_ESCAPED)
Idea
Skip WB except really required timing
1. At initializing Env objects, VM_ENV_FLAG_WB_REQUIRED is true.
2. At first local variable assignment, VM_ENV_FLAG_WB_REQUIRED
is true, we remember this Env object forcibly. And turn off this
flag.
3. At next local variable assignment, VM_ENV_FLAG_WB_REQUIRED
is false, so we can ignore WB protection.
4. At GC marking for this Env object, we turn on
VM_ENV_FLAG_WB_REQUIRED and goto (2).
Very danger technique because it depends on GC implementation
NaĂŻve code
#define VM_EP_IN_HEAP_P(th, ep) (!((th)->stack <= (ep)
&& (ep) < ((th)->stack + (th)->stack_size)))
vm_env_write(const VALUE *ep, int index, VALUE v) {
if (VM_EP_IN_HEAP_P(ep)) {
RB_OBJ_WRITE(VM_ENV_EP_ENVVAL(ep), ep-idx, val);
}
else {
*(ep - idx) = val;
}
}
Final code
vm_env_write(const VALUE *ep, int index, VALUE v) {
VALUE flags = ep[VM_ENV_DATA_INDEX_FLAGS];
if (LIKELY((flags & VM_ENV_FLAG_WB_REQUIRED) == 0)) {
*(ep - idx) = val; /* mostly used */
}
else {
/* remember env value forcibly */
vm_env_write_slowpath(ep, index, v);
}
}
Benchmark result
Bug #10212 MRI is not for lambda calculus
lc_fizzbuzz with MRI versions
0
50
100
150
ruby_2_0 ruby_2_1 ruby_2_2 ruby_2_3 trunk
Executiontime(sec)
app_lc_fizzbuzz
Bug #10212 MRI is not for lambda calculus
lc_fizzbuzz with MRI, JRuby, mruby
36.976
18.706
40.185
0
10
20
30
40
50
trunk jruby mruby
Executiontime(sec)
app_lc_fizzbuzz
Summary
•Ruby 2.4.0 has many improvements
•Now Proc (Env) objects are WB protected
and we have more faster GC (marking)
•My ideas allow to protect Env objects
without big performance impact
Thank you for your attention
Koichi Sasada
<ko1@cookpad.com>

Weitere ähnliche Inhalte

Was ist angesagt?

How to Begin Developing Ruby Core
How to Begin Developing Ruby CoreHow to Begin Developing Ruby Core
How to Begin Developing Ruby CoreHiroshi SHIBATA
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...bobmcwhirter
 
TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyistsbobmcwhirter
 
JRuby @ Boulder Ruby
JRuby @ Boulder RubyJRuby @ Boulder Ruby
JRuby @ Boulder RubyNick Sieger
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torqueboxrockyjaiswal
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)goccy
 
Fiber in the 10th year
Fiber in the 10th yearFiber in the 10th year
Fiber in the 10th yearKoichi Sasada
 
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
MongoUK 2011 - Rplacing RabbitMQ with MongoDBMongoUK 2011 - Rplacing RabbitMQ with MongoDB
MongoUK 2011 - Rplacing RabbitMQ with MongoDBBoxed Ice
 
Concurrency in Python
Concurrency in PythonConcurrency in Python
Concurrency in PythonMosky Liu
 
TorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyTorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyBruno Oliveira
 
Mасштабирование микросервисов на Go, Matt Heath (Hailo)
Mасштабирование микросервисов на Go, Matt Heath (Hailo)Mасштабирование микросервисов на Go, Matt Heath (Hailo)
Mасштабирование микросервисов на Go, Matt Heath (Hailo)Ontico
 
Pfm technical-inside
Pfm technical-insidePfm technical-inside
Pfm technical-insideiyatomi takehiro
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Charles Nutter
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyBruno Oliveira
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseChristian Melchior
 
Loom and concurrency latest
Loom and concurrency latestLoom and concurrency latest
Loom and concurrency latestSrinivasan Raghavan
 
Ruby Concurrency and EventMachine
Ruby Concurrency and EventMachineRuby Concurrency and EventMachine
Ruby Concurrency and EventMachineChristopher Spring
 
DataMapper on Infinispan
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on InfinispanLance Ball
 
Managing large and distributed Eclipse server applications.
Managing large and distributed Eclipse server applications.Managing large and distributed Eclipse server applications.
Managing large and distributed Eclipse server applications.Gunnar Wagenknecht
 
RubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mrubyRubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mrubyyamanekko
 

Was ist angesagt? (20)

How to Begin Developing Ruby Core
How to Begin Developing Ruby CoreHow to Begin Developing Ruby Core
How to Begin Developing Ruby Core
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyists
 
JRuby @ Boulder Ruby
JRuby @ Boulder RubyJRuby @ Boulder Ruby
JRuby @ Boulder Ruby
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torquebox
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
 
Fiber in the 10th year
Fiber in the 10th yearFiber in the 10th year
Fiber in the 10th year
 
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
MongoUK 2011 - Rplacing RabbitMQ with MongoDBMongoUK 2011 - Rplacing RabbitMQ with MongoDB
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
 
Concurrency in Python
Concurrency in PythonConcurrency in Python
Concurrency in Python
 
TorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyTorqueBox - When Java meets Ruby
TorqueBox - When Java meets Ruby
 
Mасштабирование микросервисов на Go, Matt Heath (Hailo)
Mасштабирование микросервисов на Go, Matt Heath (Hailo)Mасштабирование микросервисов на Go, Matt Heath (Hailo)
Mасштабирование микросервисов на Go, Matt Heath (Hailo)
 
Pfm technical-inside
Pfm technical-insidePfm technical-inside
Pfm technical-inside
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
 
Loom and concurrency latest
Loom and concurrency latestLoom and concurrency latest
Loom and concurrency latest
 
Ruby Concurrency and EventMachine
Ruby Concurrency and EventMachineRuby Concurrency and EventMachine
Ruby Concurrency and EventMachine
 
DataMapper on Infinispan
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on Infinispan
 
Managing large and distributed Eclipse server applications.
Managing large and distributed Eclipse server applications.Managing large and distributed Eclipse server applications.
Managing large and distributed Eclipse server applications.
 
RubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mrubyRubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mruby
 

Andere mochten auch

How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheLeslie Samuel
 
20170302 tryswift tasting_tests
20170302 tryswift tasting_tests20170302 tryswift tasting_tests
20170302 tryswift tasting_testsKazuaki Matsuo
 
Information sharing and Experience consistency at Cookpad mobile application
Information sharing and Experience consistency at Cookpad mobile applicationInformation sharing and Experience consistency at Cookpad mobile application
Information sharing and Experience consistency at Cookpad mobile applicationichiko_revjune
 
EL EFECTO DE LAS HERRAMIENTAS TECNOLÓGICAS EN EL APRENDIZAJE
EL EFECTO DE LAS HERRAMIENTAS TECNOLÓGICAS EN EL APRENDIZAJEEL EFECTO DE LAS HERRAMIENTAS TECNOLÓGICAS EN EL APRENDIZAJE
EL EFECTO DE LAS HERRAMIENTAS TECNOLÓGICAS EN EL APRENDIZAJEEliani Cardenas Benitez
 
Goでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 Spring
Goでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 SpringGoでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 Spring
Goでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 SpringYahoo!デベロッパーネットワーク
 
Design in Tech Report 2017
Design in Tech Report 2017Design in Tech Report 2017
Design in Tech Report 2017John Maeda
 
Secret of body language by Ritesh Gupta
Secret of body language by Ritesh GuptaSecret of body language by Ritesh Gupta
Secret of body language by Ritesh GuptaRitesh Gupta
 
Congress seeks metrics for the NIST Cybersecurity Framework
Congress seeks metrics for the NIST Cybersecurity FrameworkCongress seeks metrics for the NIST Cybersecurity Framework
Congress seeks metrics for the NIST Cybersecurity FrameworkDavid Sweigert
 
DAR Resposta - Guia para famĂ­lias apĂłs o diagnĂłstico de autismo
DAR Resposta - Guia para famĂ­lias apĂłs o diagnĂłstico de autismoDAR Resposta - Guia para famĂ­lias apĂłs o diagnĂłstico de autismo
DAR Resposta - Guia para famĂ­lias apĂłs o diagnĂłstico de autismoSara Martins
 
TEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkTEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkVolker Hirsch
 
English Prefixes to Improve Your Vocabulary
English Prefixes to Improve Your VocabularyEnglish Prefixes to Improve Your Vocabulary
English Prefixes to Improve Your VocabularyKelly Tracy
 
White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care
White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care	White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care
White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care Swords to Plowshares
 
Michael Collins - TBEX International 2017 - How to sell your blog to sponsors...
Michael Collins - TBEX International 2017 - How to sell your blog to sponsors...Michael Collins - TBEX International 2017 - How to sell your blog to sponsors...
Michael Collins - TBEX International 2017 - How to sell your blog to sponsors...TravelMedia.ie
 
Crisi econòmica i salut infantil. 2017
Crisi econòmica i salut infantil. 2017Crisi econòmica i salut infantil. 2017
Crisi econòmica i salut infantil. 2017Pediatriadeponent
 
The social care common inspection framework (SCCIF): an introduction
The social care common inspection framework (SCCIF): an introductionThe social care common inspection framework (SCCIF): an introduction
The social care common inspection framework (SCCIF): an introductionOfsted
 
結果を出すチームビルディング術
結果を出すチームビルディング術結果を出すチームビルディング術
結果を出すチームビルディング術Mao Ohnishi
 
26 Reasons You Need an MPS Assessment
26 Reasons You Need an MPS Assessment26 Reasons You Need an MPS Assessment
26 Reasons You Need an MPS AssessmentChief Optimist
 
Zero Suicide in Healthcare International Declaration (March 2016)
Zero Suicide in Healthcare International Declaration (March 2016)Zero Suicide in Healthcare International Declaration (March 2016)
Zero Suicide in Healthcare International Declaration (March 2016)David Covington
 
App Store Optimization For Extreme Newbies (Do not read if you're on a diet!)
App Store Optimization For Extreme Newbies (Do not read if you're on a diet!)App Store Optimization For Extreme Newbies (Do not read if you're on a diet!)
App Store Optimization For Extreme Newbies (Do not read if you're on a diet!)AppTweak
 

Andere mochten auch (20)

How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 
20170302 tryswift tasting_tests
20170302 tryswift tasting_tests20170302 tryswift tasting_tests
20170302 tryswift tasting_tests
 
Information sharing and Experience consistency at Cookpad mobile application
Information sharing and Experience consistency at Cookpad mobile applicationInformation sharing and Experience consistency at Cookpad mobile application
Information sharing and Experience consistency at Cookpad mobile application
 
EL EFECTO DE LAS HERRAMIENTAS TECNOLÓGICAS EN EL APRENDIZAJE
EL EFECTO DE LAS HERRAMIENTAS TECNOLÓGICAS EN EL APRENDIZAJEEL EFECTO DE LAS HERRAMIENTAS TECNOLÓGICAS EN EL APRENDIZAJE
EL EFECTO DE LAS HERRAMIENTAS TECNOLÓGICAS EN EL APRENDIZAJE
 
Goでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 Spring
Goでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 SpringGoでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 Spring
Goでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 Spring
 
Design in Tech Report 2017
Design in Tech Report 2017Design in Tech Report 2017
Design in Tech Report 2017
 
Secret of body language by Ritesh Gupta
Secret of body language by Ritesh GuptaSecret of body language by Ritesh Gupta
Secret of body language by Ritesh Gupta
 
Congress seeks metrics for the NIST Cybersecurity Framework
Congress seeks metrics for the NIST Cybersecurity FrameworkCongress seeks metrics for the NIST Cybersecurity Framework
Congress seeks metrics for the NIST Cybersecurity Framework
 
DAR Resposta - Guia para famĂ­lias apĂłs o diagnĂłstico de autismo
DAR Resposta - Guia para famĂ­lias apĂłs o diagnĂłstico de autismoDAR Resposta - Guia para famĂ­lias apĂłs o diagnĂłstico de autismo
DAR Resposta - Guia para famĂ­lias apĂłs o diagnĂłstico de autismo
 
TEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkTEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of Work
 
English Prefixes to Improve Your Vocabulary
English Prefixes to Improve Your VocabularyEnglish Prefixes to Improve Your Vocabulary
English Prefixes to Improve Your Vocabulary
 
White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care
White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care	White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care
White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care
 
Michael Collins - TBEX International 2017 - How to sell your blog to sponsors...
Michael Collins - TBEX International 2017 - How to sell your blog to sponsors...Michael Collins - TBEX International 2017 - How to sell your blog to sponsors...
Michael Collins - TBEX International 2017 - How to sell your blog to sponsors...
 
Crisi econòmica i salut infantil. 2017
Crisi econòmica i salut infantil. 2017Crisi econòmica i salut infantil. 2017
Crisi econòmica i salut infantil. 2017
 
Johnson & Johnson Scholarship for BDPA Students
Johnson & Johnson Scholarship for BDPA StudentsJohnson & Johnson Scholarship for BDPA Students
Johnson & Johnson Scholarship for BDPA Students
 
The social care common inspection framework (SCCIF): an introduction
The social care common inspection framework (SCCIF): an introductionThe social care common inspection framework (SCCIF): an introduction
The social care common inspection framework (SCCIF): an introduction
 
結果を出すチームビルディング術
結果を出すチームビルディング術結果を出すチームビルディング術
結果を出すチームビルディング術
 
26 Reasons You Need an MPS Assessment
26 Reasons You Need an MPS Assessment26 Reasons You Need an MPS Assessment
26 Reasons You Need an MPS Assessment
 
Zero Suicide in Healthcare International Declaration (March 2016)
Zero Suicide in Healthcare International Declaration (March 2016)Zero Suicide in Healthcare International Declaration (March 2016)
Zero Suicide in Healthcare International Declaration (March 2016)
 
App Store Optimization For Extreme Newbies (Do not read if you're on a diet!)
App Store Optimization For Extreme Newbies (Do not read if you're on a diet!)App Store Optimization For Extreme Newbies (Do not read if you're on a diet!)
App Store Optimization For Extreme Newbies (Do not read if you're on a diet!)
 

Ähnlich wie Ruby 2.4 Internals

Experiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyMatthew Gaudet
 
Writing a Gem with native extensions
Writing a Gem with native extensionsWriting a Gem with native extensions
Writing a Gem with native extensionsTristan Penman
 
Grow and Shrink - Dynamically Extending the Ruby VM Stack
Grow and Shrink - Dynamically Extending the Ruby VM StackGrow and Shrink - Dynamically Extending the Ruby VM Stack
Grow and Shrink - Dynamically Extending the Ruby VM StackKeitaSugiyama1
 
introduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraformintroduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraformniyof97
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012rivierarb
 
Fighting Against Chaotically Separated Values with Embulk
Fighting Against Chaotically Separated Values with EmbulkFighting Against Chaotically Separated Values with Embulk
Fighting Against Chaotically Separated Values with EmbulkSadayuki Furuhashi
 
Linux kernel bug hunting
Linux kernel bug huntingLinux kernel bug hunting
Linux kernel bug huntingAndrea Righi
 
Lp seminar
Lp seminarLp seminar
Lp seminarguestdff961
 
MacRuby, an introduction
MacRuby, an introductionMacRuby, an introduction
MacRuby, an introductionOlivier Gutknecht
 
Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby.toster
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part IEugene Lazutkin
 
Code lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzCode lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzIvan Krylov
 
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...chen yuki
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialTom Croucher
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevMattias Karlsson
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deploymentThilo Utke
 
JavaScript in 2015
JavaScript in 2015JavaScript in 2015
JavaScript in 2015Igor Laborie
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN StackTroy Miles
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVMJung Kim
 

Ähnlich wie Ruby 2.4 Internals (20)

Experiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRuby
 
New features in Ruby 2.5
New features in Ruby 2.5New features in Ruby 2.5
New features in Ruby 2.5
 
Writing a Gem with native extensions
Writing a Gem with native extensionsWriting a Gem with native extensions
Writing a Gem with native extensions
 
Grow and Shrink - Dynamically Extending the Ruby VM Stack
Grow and Shrink - Dynamically Extending the Ruby VM StackGrow and Shrink - Dynamically Extending the Ruby VM Stack
Grow and Shrink - Dynamically Extending the Ruby VM Stack
 
introduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraformintroduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraform
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
 
Fighting Against Chaotically Separated Values with Embulk
Fighting Against Chaotically Separated Values with EmbulkFighting Against Chaotically Separated Values with Embulk
Fighting Against Chaotically Separated Values with Embulk
 
Linux kernel bug hunting
Linux kernel bug huntingLinux kernel bug hunting
Linux kernel bug hunting
 
Lp seminar
Lp seminarLp seminar
Lp seminar
 
MacRuby, an introduction
MacRuby, an introductionMacRuby, an introduction
MacRuby, an introduction
 
Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part I
 
Code lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzCode lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf Linz
 
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
 
JavaScript in 2015
JavaScript in 2015JavaScript in 2015
JavaScript in 2015
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
 

KĂźrzlich hochgeladen

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
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...DianaGray10
 
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 FresherRemote DBA Services
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
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 WorkerThousandEyes
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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 2024The Digital Insurer
 
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 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

KĂźrzlich hochgeladen (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
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...
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Ruby 2.4 Internals

  • 1. Ruby 2.4 Internals Koichi Sasada ko1@cookpad.com
  • 2.
  • 3.
  • 4. Note: Ruby 2.4.0 has several bugs. Note2: No x.y.0 doesn’t have several bugs.
  • 6. New features written in a release announcement • Introduce hash table improvement (by Vladimir Makarov) • Binding#irb: Start a REPL session similar to binding.pry • Unify Fixnum and Bignum into Integer • String supports Unicode case mappings • Performance improvements • Array#max, Array#min • Regexp#match? • speed up instance variable access • Debugging • Thread#report_on_exception and Thread.report_on_exception • Thread deadlock detection now shows threads with their backtrace and dependency • Other notable changes since 2.3 • Support OpenSSL 1.1.0 (drop support for 0.9.7 or prior) • ext/tk is now removed from stdlib Feature #8539 • XMLRPC is now removed from stdlib Feature #12160
  • 7. Ruby 2.4 Internals Koichi Sasada ko1@cookpad.com
  • 10.
  • 11.
  • 12.
  • 14.
  • 15. Bug #10212 MRI is not for lambda calculus JRuby 26 sec mruby 27 sec MRI 114 sec
  • 16.
  • 18. Ruby 2.4 Internals Change block/env structs Koichi Sasada ko1@cookpad.com
  • 19. Issues 1. we need to clear rb_control_frame_t::block_iseq for every frame setup. It consumes space (a VALUE for each frame) and initializing time. 2. There are several block passing ways by ISeq (iter{...}), Proc(iter(&pr)), Symbol(iter(:sym)). However, they are not optimized (for Symbol blocks, there is only ad-hoc check code). 3. Env (and Proc, Binding) objects are not WB-protected ([Bug #10212]). Method dispatch (etc) improvements Cleanup src code Improve GC perf.
  • 21. Approaches •For (1), (2) •Introduce Block Handler (BH) •Using BH •For (3) •Introduce Write Barriers (WB) for Env objects
  • 22. WB protected or unprotected? •Ruby 2.1.0 introduced Generational GC •Only newer objects •GenGC requires “Write barriers” (WB), but MRI allows WB unprotected objects (See my past presentations for details) •WB protected objects: GenGC → Fast •WB unprotected objects: Not GenGC → Slow
  • 23. RubyVM::Env objects •Env objects represent captured local variables •Each Proc or Binding has at least one Env object •Proc object “$pr” consists of 3 Env objects a = 1 1.times{|b| 1.times{|c| $pr = Proc.new{ # you can access a, b, c } } } Proc $pr Env c=0 Env b=0 Env a=1
  • 24. RubyVM::Env objects were WB-unprotected •They were WB unprotected because: •Difficulty of implementation •Performance issue
  • 25. Performance issue Assignment performance • Ruby 2.3 or before *(ep - idx) = val; • NaĂŻve implementation #define VM_EP_IN_HEAP_P(th, ep) ÂĽ (!((th)->stack <= (ep) && ÂĽ (ep) < ((th)->stack + (th)->stack_size))) if (VM_EP_IN_HEAP_P(ep)) { RB_OBJ_WRITE(VM_ENV_EP_ENVVAL(ep), ep-idx, val); } else *(ep - idx) = val;
  • 26. Ideas 1. Lightweight escape detection 2. Skip WB except really required timing
  • 27. Idea Lightweight escape detection •Move cfp->flags to ep[0] •Introduce a VM_ENV_FLAG_ESCAPED flag to represent escaped Env. • // Before #define VM_EP_IN_HEAP_P(th, ep) (!((th)->stack <= (ep) && (ep) < ((th)->stack + (th)->stack_size))) • // After #define VM_EP_IN_HEAP_P(ep) (ep[0] & VM_ENV_FLAG_ESCAPED)
  • 28. Idea Skip WB except really required timing 1. At initializing Env objects, VM_ENV_FLAG_WB_REQUIRED is true. 2. At first local variable assignment, VM_ENV_FLAG_WB_REQUIRED is true, we remember this Env object forcibly. And turn off this flag. 3. At next local variable assignment, VM_ENV_FLAG_WB_REQUIRED is false, so we can ignore WB protection. 4. At GC marking for this Env object, we turn on VM_ENV_FLAG_WB_REQUIRED and goto (2). Very danger technique because it depends on GC implementation
  • 29. NaĂŻve code #define VM_EP_IN_HEAP_P(th, ep) (!((th)->stack <= (ep) && (ep) < ((th)->stack + (th)->stack_size))) vm_env_write(const VALUE *ep, int index, VALUE v) { if (VM_EP_IN_HEAP_P(ep)) { RB_OBJ_WRITE(VM_ENV_EP_ENVVAL(ep), ep-idx, val); } else { *(ep - idx) = val; } }
  • 30. Final code vm_env_write(const VALUE *ep, int index, VALUE v) { VALUE flags = ep[VM_ENV_DATA_INDEX_FLAGS]; if (LIKELY((flags & VM_ENV_FLAG_WB_REQUIRED) == 0)) { *(ep - idx) = val; /* mostly used */ } else { /* remember env value forcibly */ vm_env_write_slowpath(ep, index, v); } }
  • 32. Bug #10212 MRI is not for lambda calculus lc_fizzbuzz with MRI versions 0 50 100 150 ruby_2_0 ruby_2_1 ruby_2_2 ruby_2_3 trunk Executiontime(sec) app_lc_fizzbuzz
  • 33. Bug #10212 MRI is not for lambda calculus lc_fizzbuzz with MRI, JRuby, mruby 36.976 18.706 40.185 0 10 20 30 40 50 trunk jruby mruby Executiontime(sec) app_lc_fizzbuzz
  • 34. Summary •Ruby 2.4.0 has many improvements •Now Proc (Env) objects are WB protected and we have more faster GC (marking) •My ideas allow to protect Env objects without big performance impact
  • 35. Thank you for your attention Koichi Sasada <ko1@cookpad.com>