InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Future of the Threading and Garbage Collection in Ruby - Interview with Koichi Sasada

Posted by Werner Schuster on Jul 31, 2009

Sections
Development,
Architecture & Design
Topics
Dynamic Languages ,
Runtimes ,
Scripting ,
Performance & Scalability ,
Ruby
Tags
Ruby1.9 ,
Threading ,
GarbageCollection ,
Virtual Machines ,
MVM

Ruby 1.9.2 is due by the end of the year - InfoQ used the release of 1.9.2 Preview 1 as an occasion to talk to Ruby 1.9.x VM maintainer Koichi Sasada about the future of the VM, Threading and the Garbage Collector.

InfoQ: At RubyConf'08 you mentioned that there were some optimizations in 1.9.x that are turned off by default, but you might turn them on in 1.9.2. What's the status of this work?
Koichi Sasada
: In fact, 1.9.2 doesn't turn on optimizations. It seems to need more experience to turn on such optimizations. In short, there is no time to make experiments.
Some other trivial optimizations will be included. If I can make a time to work on it, I want to implement some other ideas such as Proc#call optimization.

InfoQ: Ruby 1.9.2 Preview 1 had the longlife GC patch applied. As I understand, a GC run for normal objects should now be faster since it ignores objects in the long lived object space (until a full GC run - which includes long lived objects - happens). Is that correct?
Koichi Sasada: Yes. Nari-san made it. Mainly, some node objects belong to generational objects. Some nodes were used as inline cache to improve VM performance. This change ignore such inline cache objects to mark on GC.
However, I re-write inline cache codes to avoid node objects. This means that inline cache code no longer use node objects. Accordingly, this GC optimization have few improvement.

InfoQ: It seems like the longlife GC patch is the first step towards a generational GC, particularly the introduction of code for handling write barriers and remembered sets. Is a generational GC possible for 1.9.2?
Koichi Sasada: No. It is limited to "uncovered" objects. This is means that the objects that are not touched from C extension libraries. If a part of code touches this object and forgets to make a write barrier, it can cause a critical bug such as causing SEGV. CRuby (Matz) may not permit such a change.

Another Japanese researcher (student) is working on auto write-barrier (WB) insertion for GC implementations that need WBs. If it succeeds, generational GC (or incremental GC, also) is no longer a dream :)

InfoQ: What are the difficulties in making a generational GC for the Ruby 1.9.x VM? I suppose moving objects might be an issue - would that create problems with native extensions?

Koichi Sasada
: Problem is, as I wrote, GC techniques needs completeness. If someone forgets to add a write barrier, it should be serious problem.
In this background, another Japanese researcher proposed "mostly mark & compaction GC". This technique works as conservative, so it doesn't need completeness (of course, GC implementation should be complete. I mean that no changes are needed for extension library interface).

InfoQ: - The Unladen Swallow project aims to remove the GIL in Python. What are your plans for the GIL (or GVL in Ruby) in 1.9.2 or future versions?
Koichi Sasada: On 1.9.2 or near future, I can't release GVL (Giant VM Lock, GIL in YARV terminology).
Far future, I'm not sure. I'm also not sure that we would be happy if GVL free threads are available. In short, it makes scripting difficult.

InfoQ: Have you looked at how MacRuby solves the GIL problem?
Koichi Sasada: Great work. I want to watch the result of programmability. If every Macruby users says they're "happy", we must change our mind :)

InfoQ: Does the GVL prevent problems with native extensions?
Koichi Sasada: GVL doesn't prevent any problem :)

In fact, my doctor thesis proposes a GVL free Ruby VM, which improves performance by CPU number. On my parallel VM, a non-thread safe method (written in C) is invoked, at first, VM acquires GVL, and process such a method, and releases GVL. In my thesis, some optimization and exception safe techniques are written (unfortunately, it is written in Japanese).

On my parallel VM, VM features are thread-free, this means that parallel execution is available. However, many thread-unsafe methods remain, for example methods of String, Array and more built-in classes. This is simple (but difficult. makes buggy code easy) work to make them thread-safe (but many efforts are needed). So I can say that "it is possible, of course" from implementation side.

However, as I wrote, I'm not sure it makes us happy from language design side.

Currently, we are working on MVM (Multi-Virtual Machine) project sponsored by Sun Microsystems, Inc. This project makes it possible to invoke many VMs in a process. All VMs can run in parallel. I think it is more preferable to manipulate parallelism than thread, of course if MVM operations needs low cost enough. This cost is one of our research goals. On MVM side, we don't need to care about thread-safety, but VM communications.

This is only research project, but I want to ship off practical implementation.

In another projects, we are planning to utilize parallelism. This is under consideration, but I hope I can show such a techniques at next RubyConf.

 

No comments

Watch Thread Reply

Educational Content

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.