arXiv:2609.01502cs.PLSep 2026

Manuscript Offprint

arXiv:2609.01502

Support Local Variables

Maxwell Bernstein, Takashi Kokubun, Aaron Patterson, Si Xing "Alan" Wu, Kevin Menard

Maxwell Bernstein

Shopify

Boston, USA

acm@bernsteinbear.com

Takashi Kokubun

Shopify

Cupertino, USA

takashikkbn@gmail.com

Aaron Patterson

Shopify

Seattle, USA

aaron.patterson@gmail.com

Si Xing (Alan) Wu

Shopify

Ottawa, USA

paper@alanwu.email

Abstract

Ruby is a dynamically typed and object-oriented programming language. Its primary implementation, CRuby, contains a bytecode virtual machine and a mature lazy basic block versioning (LBBV) just-in-time (JIT) compiler called YJIT.

In order to both implement more advanced optimizations than YJIT supports and also encourage more outside contributions, we present a new method-based JIT called ZJIT. Like YJIT, ZJIT compiles from bytecode to machine code. Unlike YJIT, ZJIT has multiple global and local optimization passes.

ZJIT's high-level intermediate representation is in static single assignment (SSA) form. In order to optimize Ruby's local variables, ZJIT lifts local variables into SSA values. This is a departure from how other Ruby compilers handle locals: other JIT compilers either leave local variables as memory loads and stores or do advanced partial evaluation to recover SSA values from memory.

While implementing locals, we (re-)discovered what features make local variables in Ruby especially challenging to compile correctly and efficiently. We demonstrate these features and illustrate how we solved these problems in ZJIT.

CCS Concepts: • Software and its engineering → Just-in-time compilers; Runtime environments.

Keywords: Just-in-time compiler, JIT, compiler, Ruby, CRuby, virtual machine

ACM Reference Format:

Maxwell Bernstein, Takashi Kokubun, Aaron Patterson, Si Xing (Alan) Wu, and Kevin Menard. 2026. Support Local Variables. In Proceedings of the 18th ACM SIGPLAN International Workshop on Virtual Machines and Intermediate Languages (VMIL '26), October 4–9, 2026, Oakland, CA, USA. ACM, New York, NY, USA, 10 pages. https://doi.org/10.1145/3840562.3844969

Figure

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

VMIL '26, Oakland, CA, USA

© 2026 Copyright held by the owner/author(s).

ACM ISBN 979-8-4007-2932-4/2026/10

https://doi.org/10.1145/3840562.3844969

Kevin Menard

Shopify

Boston, USA

acm@kevin.nirvdrum.com

1 Introduction

Just-in-time compilers accelerate programs either immediately before or interleaved with execution. They are commonly used to efficiently implement dynamic languages because very little information is available ahead of time.

JIT compilers are often a second implementation of the source language. In order to execute code faster, they implement the language differently than the existing implementation. They may even represent objects differently, including the method call frames.

One oft-used language feature is local variables, which are used for storing temporary values in a method call frame. Locals are so common that most developers will never take pause before using them. However, Ruby semantics for local variables have presented many challenges for our new JIT compiler, ZJIT.

Unlike the existing compiler, YJIT, ZJIT does not flush and re-load local variables from the VM frame. Instead, ZJIT lifts local variables to SSA values and uses speculation and deoptimization to recover from mispredictions. For the last year, we have incrementally discovered more semantic dark corners that we need to faithfully implement in our new compiler for compatibility.

We implement this compiler in the context of CRuby’s bytecode interpreter, YARV. Both are described in Section 2. It is compiled and integrated much the same way as YJIT. It has similar compatibility as YJIT; we pass the Ruby test suite and can successfully run many large web applications, with only a handful of known bugs.

This speculative approach for local variables is novel in Ruby compilers: Ruby allows so much reflection that its other major JIT-compiled implementations (YJIT, JRuby, and TruffleRuby) use different approaches, described in Section 7. Our SSA lifting approach has two major motivations.

First, it helps us better optimize our high-level intermediate representation: for example, delete redundant type checks, eliminate memory loads and stores, and more effectively apply value numbering.

Second, because we are grafting a new compiler onto an existing runtime, we must work within the context of a large mass of existing C library code, little of which was designed

Maxwell Bernstein, Takashi Kokubun, Aaron Patterson, Si Xing (Alan) Wu, and Kevin Menard

with JIT compilation in mind. Therefore, a partial-evaluation-based approach would recover minimal information about local variables. We have found it reasonable to add callback “hooks” to deoptimization points in the existing C codebase.

This paper will discuss existing implementation background in Section 2, introduce ZJIT and its architecture in Section 3, and present challenges for implementing local variables with Ruby-specific semantics in ZJIT in Section 4. Then it will present its current (and projected future) solutions to these problems in Section 5.

References (18)