16
Digging into Ruby guts

Digging into Ruby Guts

  • Upload
    -

  • View
    381

  • Download
    0

Embed Size (px)

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.

Citation preview

Page 1: Digging into Ruby Guts

Digging into Ruby guts

Page 2: 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

Page 3: Digging into Ruby Guts

How Ruby reads your code

Page 4: Digging into Ruby Guts

How Ruby executes your code

Page 5: Digging into Ruby Guts

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

Page 6: Digging into Ruby Guts

How it parses?

● Bison (Yacc descendant)● Samples of grammar rules● Ruby code roadmap:

– Ruby source code

– Tokens

– AST Nodes

– YARV Instructions

Page 7: Digging into Ruby Guts

And we need to go deeper

Page 8: Digging into Ruby Guts

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 をプッシュする )

Page 9: Digging into Ruby Guts

How it works?

Little workshop

Page 10: Digging into Ruby Guts

RubyVM module

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

● http://www.ruby-doc.org/core-2.0.0/RubyVM.html

● Container for RubyVM::InstructionSequence

Page 11: Digging into Ruby Guts

Benefits

● Speed up your templates by precompiling● Use functional style programming● Trace your program if bug is hard to find

Page 12: Digging into Ruby Guts

Bytecode Compilation

Rubinius is not needed anymore. At least, runtime.

(little demonstration)

https://github.com/haml/haml/issues/674https://gist.github.com/Paxa/321be47319327e5e7058

Page 13: Digging into Ruby Guts

Tail Call Optimization

Just for functional programming addicts(another little demonstration)

Page 14: Digging into Ruby Guts

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

Page 15: Digging into Ruby Guts

We are hiring. Take a contacts ;)

Page 16: Digging into Ruby Guts

Mikhail [email protected]

Skype: mikhail.bortnyk

https://github.com/vessi/rubymeditation3_yarv