Building a More Efficient Ruby Interpreter

Google Tech Talk December 11, 2009 ABSTRACT Presented by Hongli Lai and Ninh Bui from Phusion. The Ruby programming language powers a significant portion of today’s websites and is still growing in popularity. However, its implementation is not as efficient as it could be, and in this talk we will explain how Ruby Enterprise Edition addresses some of these issues. Ruby has a relatively high memory usage compared to eg C++, and we’ve found that this is partially caused by the fact that memory for program code is not shared between multiple interpreter instances as is possible in C++ programs. One way to battle this problem is by leveraging copy-on-write virtual memory semantics. However, Ruby’s garbage collector hostile to this technique. We will explain how we’ve made the garbage collector copy-on-write friendly, how we’ve leveraged Linux kernel features during the development of this enhancement, how our Phusion Passenger web app deployment product leverages copy-on-write and how much memory one can save. Another problem the fact that Ruby’s userspace threading implementation severely degrades in performance in the face of large thread stacks. Several contributors have identified the source of this problem: Ruby copies the entire thread stack during a context switch. We will explain how they’ve identified this problem, what obstacles we’ve faced during the development of a patch and just how significant the improvement is.

Get the book now