Ruby Video
Talks
Speakers
Events
Topics
Leaderboard
Sign in
Talks
Speakers
Events
Topics
Use
Analytics
Sign in
Suggest modification to this talk
Title
Description
Compiling Ruby by Kevin Newton Since Ruby 2.3 and the introduction of RubyVM::InstructionSequence::load_iseq, we've been able to programmatically load ruby bytecode. By divorcing the process of running YARV byte code from the process of compiling ruby code, we can take advantage of the strengths of the ruby virtual machine while simultaneously reaping the benefits of a compiler such as macros, type checking, and instruction sequence optimizations. This can make our ruby faster and more readable! This talk demonstrates how to integrate this into your own workflows and the exciting possibilities this enables.
Date
Summary
Markdown supported
In this talk titled 'Compiling Ruby' presented by Kevin Newtown at RubyConf 2017, the focus is on understanding the Ruby execution process and how recent enhancements to Ruby can improve performance and readability. The discussion begins with the execution flow from source code to output, detailing how Ruby interprets a program through various stages: - **Code Requirement**: Ruby starts by requiring code to be executed, which is subsequently read and tokenized. - **Tokenization**: This stage involves breaking down the code into recognizable tokens, although semantic meaning is not applied yet. - **Abstract Syntax Tree (AST)**: A tree structure is formed from the tokens, adding context and meaning to the code. - **Instruction Sequences**: With Ruby 1.9, the process evolved to create instruction sequences from the AST, allowing more efficient execution. Newtown highlights the evolution introduced in Ruby 2.3, which allows compiled instruction sequences to be saved as binary files for later execution using the newly added `RubyVM::InstructionSequence` API. This enhancement enables: - The possibility to load pre-compiled instruction sequences, circumventing the initial compilation steps. - Improved performance through intelligent execution of instruction sequences, facilitating optimizations within Ruby’s virtual machine. The presentation features examples of the `compile_file` method and how to utilize the `to_binary` function, followed by considerations around machine-specific binaries. The importance of checking whether files are up to date before recompiling is also discussed. Kevin also introduces practical applications, such as the 'BootSnap' gem, which showcases efficient loading of instruction sequences and presents an innovative gem called 'Vernacular'. This gem allows developers to implement their custom Gsub methods that hook into the compilation pipeline. Newtown emphasizes: - The potential for Ruby to extend capabilities through flexible operator overriding and introduce efficiency back into the coding process. - The ability to investigate and manipulate the Abstract Syntax Tree for better performance and code clarity. - The importance of creating a robust framework where programming constraints can be defined for better functionality. In conclusion, Newtown encourages the Ruby community to explore new practices to enhance Ruby’s efficiency and maintain its usability in an evolving programming landscape, urging for continued discussions on innovative methods to improve code quality and performance.
Suggest modifications
Cancel