John Lam 1997 — 2026

Why another Ruby to CLR bridge?

There are at least two other Ruby to CLR bridges. There is the Salty Pickle bridge written by John Pierce and Ben Schroeder, and there is another bridge written by Thomas Sondergaard. These bridges heavily leverage the existing CLR Reflection API and its dynamic method invocation infrastructure.

Because of this, these bridges are not particularly efficient in either space or time. Reflective method invocation is a very heavyweight operation, as these benchmarks will bear out. Furthermore, if value types are marshaled across the boundary, these objects will be boxed and placed on the CLR GC heap, resulting in an increase in memory pressure.

Writing my own bridge lets me fix these problems, and it gave me an excuse to study the Ruby extension interfaces and the CLR V2 lightweight code generation API. It also gave me an excuse to try out Stan Lippman’s excellent work in fixing the Managed C++ syntax in Whidbey.

My bridge addresses method invocation performance by generating CIL stubs on the fly using the new DynamicMethod API in Whidbey. These CIL stubs are directly bound to the Ruby object’s methods. So once those CIL stubs have been JITed by the CLR, a method call from Ruby goes directly into managed code. The only overhead is that incurred by marshaling parameters from their Ruby representation to the corresponding CLR representation.

Update:

From my comments, Anson Tsao mentioned a couple of other folks I should credit for the MC++ syntax:

There are a couple of other folks you should credit for the C++/CLI design. Herb Sutter and Brandon Bray. Herb was responsible for much of the syntax innovations such as context sensitive keywords (ref class), and Brandon was responsible for writing the language specification and probably knows more about language design details than anyone else.

2 archived reader comments

Anson Tsao (2005/11/02)

John, There are a couple of other folks you should credit for the C++/CLI design. Herb Sutter and Brandon Bray. Herb was responsible for much of the syntax innovations such as context sensitive keywords (ref class), and Brandon was responsible for writing the language specification and probably knows more about language design details than anyone else.

Jamiela (2006/09/27)

I like your story, how can I see ruby briges in preson?