digging into ruby guts
DESCRIPTION
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.TRANSCRIPT
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 will understand more, you can help community
● Improve your knowledge of computer science● Just for fun, you know
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 lexical analyzerhttp://www.ruby-doc.org/stdlib-1.9.3/libdoc/ripper/rdoc/Ripper.html
How it parses?
● Bison (Yacc descendant)● Samples of grammar rules● Ruby code roadmap:
– Ruby source code
– Tokens
– AST Nodes
– YARV Instructions
And we need to go deeper
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 をプッシュする )
How it works?
Little workshop
RubyVM module
● Well-documented, you know, as before (スタッ クに self をプッシュする )
● http://www.ruby-doc.org/core-2.0.0/RubyVM.html
● Container for RubyVM::InstructionSequence
Benefits
● Speed up your templates by precompiling● Use functional style programming● Trace your program if bug is hard to find
Bytecode Compilation
Rubinius is not needed anymore. At least, runtime.
(little demonstration)
https://github.com/haml/haml/issues/674https://gist.github.com/Paxa/321be47319327e5e7058
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-forum.com/forum/ruby-core● http://rxr.whitequark.org/mri/source/iseq.c
We are hiring. Take a contacts ;)