Digging into Ruby guts
For why?
●

Become a better developer
–

If you know internals of your language, you'll use it
more efficient

–

If you w...
How Ruby reads your code
How Ruby executes your code
What is the tokens?
10.times { |n| puts n }
●

tINTEGER

●

tIDENTIFIER

●

keyword_do, |tIDENTIFIER|
Ripper class — Ruby ...
How it parses?
●

Bison (Yacc descendant)

●

Samples of grammar rules

●

Ruby code roadmap:
–

Ruby source code

–

Toke...
And we need to go deeper
What the hell is YARV?
YARV (Yet Another Ruby Virtual Machine)
–

Stack-oriented virtual machine

–

Developed by Koichi S...
How it works?

Little workshop
RubyVM module
●

Well-documented, you know, as before ( スタッ
クに self をプッシュする )

●

http://www.ruby-doc.org/core-2.0.0/RubyV...
Benefits
●

Speed up your templates by precompiling

●

Use functional style programming

●

Trace your program if bug is ...
Bytecode Compilation
Rubinius is not needed anymore. At least,
runtime.
(little demonstration)
https://github.com/haml/ham...
Tail Call Optimization

Just for functional programming addicts
(another little demonstration)
Where to find more?
●

Ruby under the microscope

●

Ruby sources

●

http://lmgtfy.com/?q=RubyVM

●

https://www.ruby-for...
We are hiring. Take a contacts ;)
Mikhail Bortnyk
vessimir@gmail.com
Skype: mikhail.bortnyk
https://github.com/vessi/rubymeditation3_yarv
Upcoming SlideShare
Loading in …5
×

Digging into Ruby Guts

675 views

Published on

Presentation about how Ruby processes and executes your code and how it can help you to find bugs and speed up some of your code.

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
675
On SlideShare
0
From Embeds
0
Number of Embeds
73
Actions
Shares
0
Downloads
7
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Digging into Ruby Guts

  1. 1. Digging into Ruby guts
  2. 2. For why? ● Become a better developer – If you know internals of your language, you'll use it more efficient – If you will understand more, you can help community ● Improve your knowledge of computer science ● Just for fun, you know
  3. 3. How Ruby reads your code
  4. 4. How Ruby executes your code
  5. 5. What is the tokens? 10.times { |n| puts n } ● tINTEGER ● tIDENTIFIER ● keyword_do, |tIDENTIFIER| Ripper class — Ruby lexical analyzer http://www.ruby-doc.org/stdlib-1.9.3/libdoc/ripper/rdoc/Ripper.html
  6. 6. How it parses? ● Bison (Yacc descendant) ● Samples of grammar rules ● Ruby code roadmap: – Ruby source code – Tokens – AST Nodes – YARV Instructions
  7. 7. And we need to go deeper
  8. 8. What the hell is YARV? YARV (Yet Another Ruby Virtual Machine) – Stack-oriented virtual machine – Developed by Koichi Sasada (mostly) – Finally, it's double stack machine – Tracing of ruby code using YARV – Well-documented, really ( スタックに self をプッ シュする )
  9. 9. How it works? Little workshop
  10. 10. RubyVM module ● Well-documented, you know, as before ( スタッ クに self をプッシュする ) ● http://www.ruby-doc.org/core-2.0.0/RubyVM.html ● Container for RubyVM::InstructionSequence
  11. 11. Benefits ● Speed up your templates by precompiling ● Use functional style programming ● Trace your program if bug is hard to find
  12. 12. Bytecode Compilation Rubinius is not needed anymore. At least, runtime. (little demonstration) https://github.com/haml/haml/issues/674 https://gist.github.com/Paxa/321be47319327e5e7058
  13. 13. Tail Call Optimization Just for functional programming addicts (another little demonstration)
  14. 14. Where to find more? ● Ruby under the microscope ● Ruby sources ● http://lmgtfy.com/?q=RubyVM ● https://www.ruby-forum.com/forum/ruby-core ● http://rxr.whitequark.org/mri/source/iseq.c
  15. 15. We are hiring. Take a contacts ;)
  16. 16. Mikhail Bortnyk vessimir@gmail.com Skype: mikhail.bortnyk https://github.com/vessi/rubymeditation3_yarv

×