Skip to content

IronRuby 4.0.6

Latest

Choose a tag to compare

@github-actions github-actions released this 19 Nov 21:41
· 180 commits to master since this release
7fb0cbc

IronRuby 4.0.6 is mostly about speed, and it brings two features that are new and still experimental: a Ruby C API, so a C extension compiled against IronRuby's ruby.h can be required, and IronRuby in the browser on WebAssembly. The Linux x64 and Windows x64 downloads carry the C API; the browser build is made from source, and there is no WebAssembly download. Method calls got cheaper: a method that makes calls, passes its block or a splat on, uses block_given? or interpolates a String now runs without allocating a scope, and blocks, instance variables and keyword calls cost less. On the five Are-We-Fast-Yet benchmarks #215 measured, IronRuby went from 1.86 to 1.05 times CRuby's time. erubi went from 94 to 3.1 times CRuby's time, and rubocop from 60 to about 32 times. The release also fixes exceptions, threads, fibers and macOS pipes, and a list of smaller differences from CRuby.

New

  • A Ruby C API, on Linux x64 and Windows x64 (#226, #236). A C extension compiled
    against IronRuby's ruby.h can be required, and gem install builds a gem's C extension
    as CRuby does: with gcc on Linux, and on Windows with MinGW gcc, as RubyInstaller uses. With
    IRONRUBY_NATIVE_GEMS=sqlite3, the real sqlite3 gem installs, builds its extension and is
    used instead of IronRuby's own C# port. It needs a C compiler on the machine, and the
    native library libironruby-capi: the Linux x64 and Windows x64 downloads carry it (#236),
    and Util/build-capi.sh builds it for a build from source. The release workflow builds a
    small extension with mkmf against the Linux archive and calls it; the Windows archive's
    library is built there and not exercised, and the macOS archives have no C API. Of
    ruby/spec's optional/capi examples, 1,380 of 1,641 passed on Linux and 1,186 of 1,457 on
    Windows when #226 was merged. Limits (Src/Ruby/CApi/README.md):
    every object C has seen stays alive for the process, a T_DATA object's dfree never
    runs, one runtime per process can use it, and keyword arguments from C, rb_io_t, st
    tables, macOS and MSVC-built extensions are not supported yet. A function that is not
    implemented raises NotImplementedError when called. An extension built for CRuby is
    refused with a LoadError.
  • IronRuby in the browser (#211). wasm/ builds IronRuby for .NET 10's browser-wasm
    runtime, with a JavaScript API that runs Ruby code on the page or in a Web Worker and loads
    .NET assemblies at run time. Build it with wasm/build.sh (wasm/README.md); there is no
    download. On the machine that built it, the AOT bundle boots in about 1.6 s in headless
    Chromium. It is single-threaded: Thread.new, Fiber and Enumerator#next raise
    NotImplementedError. It has no processes, sockets, native extensions, YAML or RubyGems,
    and its file system is in memory.
  • require "continuation" (#212): callcc with continuations that escape. Calling a
    continuation after its callcc has returned raises NotImplementedError.

Performance

Each figure below is from the pull request named, measured there with a Release build on
Linux x64 and .NET 10 unless it says otherwise, against CRuby 4.0.9 run beside it. They come
from different machines and days, often loaded ones, so compare figures within one bullet
only. Ratios are IronRuby's time over CRuby's: lower is better, below 1 is faster than CRuby.

  • Are-We-Fast-Yet (#215, #216). On the five benchmarks #215 measured (DeltaBlue,
    Richards, Json, Bounce, Towers), the geomean went from 1.86 to 1.05; DeltaBlue from 2.23 to
    1.28, Towers from 1.90 to 0.94. #216 measured all thirteen on a 4-core machine: a geomean
    of 0.73 to 0.78 over three runs, from 0.87 at its start, with List, CD and NBody 34-41%
    faster. TruffleRuby 40.0.0 was at about 0.05 there. On another machine on 2026-11-19 the
    thirteen read 0.853 (Util/perf/LEDGER.md); the two machines do not compare.
  • Methods run without a scope more often (#215, #221, #231, #233, #234). A method that
    makes calls, has a literal block, passes &block or a splat on, has a rest parameter,
    asks block_given? or interpolates a String no longer allocates its scope unless a call
    needs it. Per call: one &block wrapper 362 → 288 ns (CRuby 112), a *args, &block
    wrapper 429 → 366 ns, a method that interpolates an Integer 208 → 167 ns (CRuby 151), and
    def m(*args) with one argument 218 → 178 ns (CRuby 131). String#lstrip takes 0.70 of
    its earlier time. inject(:+) and Array#zip now count 4.9% and 2.9% more instructions
    (#233). Each step can be turned off: IR_LIGHT_FRAMES=0, or IR_LIGHT_BLOCK_PASS,
    IR_LIGHT_SPLAT, IR_LIGHT_REST, IR_LIGHT_BLOCK_GIVEN or IR_LIGHT_INTERPOLATION
    set to 0.
  • Beyond AWFY (#218). erubi 94 → 3.1 times CRuby's time, rubocop 60 → about 32,
    nqueens 1.78 → 0.40, Struct member reads 1.98 → 0.48. Integer("x") rescue nil
    139 → 29 µs. each_slice with #next 32 → 0.9 µs a step. Hash#dig with three keys
    and lines(chomp: true) are now about CRuby's speed. erubi, rubocop and railsbench were
    timed on the branches of #218, not again after they were merged.
  • Blocks, keywords and Enumerator#next (#212). Util/bench's geomean over 67
    benchmarks went from 2.43 to 2.30 times CRuby's time. Enumerator#next over an Array is
    2.7 times as fast, a global variable read 2.5 times, Fiber.new 1.7 times.
  • Core methods written in Ruby (#221, #225, #228, #229). Per call: a.inject(:+)
    819 → 511 ns (CRuby 122), Array#dig(0, 1) 682 → 356 ns (CRuby 60), Array#sum { }
    1,421 → 868 ns (CRuby 236), Array#to_h { } 2,120 → 1,276 ns (CRuby 548). each_index
    over 1,000 elements 58-61 → 5.7-6.2 ns per element (CRuby 71). Range#sum of Integers is
    a third faster.
  • Exceptions, Integers, Strings and threads (#202, #206, #207, #208, #210, issue 89).
    • A raise rescued in place 13.0 → 10.2 µs; through 20 ensure frames 87.3 → 37.1 µs
      (CRuby 1.1 and 2.8 µs, #210).
    • Integer.sqrt of a 100,000-bit Integer 14.1-17.6 → 1.3-4.2 ms (CRuby 0.43-0.61 ms);
      String#hash of 1 KB of ASCII 699-798 → 444-608 ns (CRuby 299-455 ns, #202).
    • Integer("123", exception: false) runs 633-820 instructions instead of 1,402-1,462
      (CRuby 1,500, #206).
    • s + "x" on 100 KB of ASCII 63-71 → 43-48 µs on .NET 11 (CRuby 9-11 µs, #207).
    • A finished Thread can be garbage collected at once; the DLR and Thread.list kept
      it alive. Bytes allocated per Thread.new { }.join 6.3-7.7 → 3.1-3.2 KB (#208).

Still slow: a raise costs several times CRuby's, rescue => e still walks the CLR stack,
a Fiber is a CLR thread (a resume and yield round trip is 72 times CRuby's, #218), and
calling each, times or map on a short collection costs about twice CRuby's.
Richards and DeltaBlue are slower than CRuby. Issue #89 and Util/perf/LEDGER.md track these.

Fixed

  • Exceptions and backtraces (#204). An ensure that returns, breaks or throws ends the
    exception: $! is nil afterwards, and the next raise does not get it as its cause. A
    raise in an ensure no longer shows its method twice in the backtrace on .NET 10 and
    .NET 11. caller in a hot while loop gave line 16707566. rescue E uses a refined
    E.===. An error raised by IronRuby's C# code inside a rescue clause, such as 1/0,
    gets the rescued exception as its cause, but only while the method is interpreted (see
    Known issues).
  • Threads and fibers (#203, #208, #209). A Thread#kill sent while a thread was
    resuming a fiber could be lost, and join then hung. A Thread#raise left a wake-up
    behind, so the next sleep could return at once. A Thread#raise during a fiber switch
    could hang the resumer or make the next resume raise "attempt to resume a resumed fiber".
    With several runtimes in one process, one runtime's shutdown no longer stops another's
    fibers or threads.
  • macOS (#205). IO.pipe, IO.popen and backquotes raised
    System::EntryPointNotFoundException, since macOS has no pipe2. fcntl, open and
    ioctl read the wrong argument on Apple arm64, so IO#nonblock=, IO#fcntl, IO#ioctl
    and files created by exec redirections were wrong. spawn(cmd, fd => fd) now hands the
    descriptor over. These were checked on the CI's osx-arm64 runner; macOS is still built in
    CI and not otherwise tested.
  • Core methods (#203, #206, #212, #216, #218, #228, #229, #231), as CRuby 4.0 does:
    • "a b".split(/ /x) splits at each space, and Integer("", 1) raises "invalid radix 1".
    • [10**16, 1, -10**16].sum(0.0) is 1.0, not 0.0: sum from a Float adds Integers
      and Rationals exactly first.
    • yield 1 to { |a, b = 6, *r| } sets b to 6, and Fiber.new(foo: 1) { } raises
      ArgumentError: unknown keyword, not FiberError.
    • A BasicObject subclass that includes Enumerable or Comparable reads back its
      instance variables. Every railsbench /posts.json request failed on it.
    • "x\r".lines(chomp: true) keeps the \r. The pattern forms of any?, all?, none?
      and one? call a private ===. lambda(&b) with a passed block raises "the lambda
      method requires a literal block".
    • Hash#transform_values, Array#rotate, min_by(n), take_while, drop_while,
      to_h, uniq { } and dig give CRuby's answers and errors in more corner cases.
  • CRuby's own tests: IronRuby passes 5,430 of the 10,230 test/ruby tests that
    CRuby 4.0.9 passes, from 44.7% to 53.1% (#212).

Changed

  • Long ASCII Strings hash with SipHash-1-3 (#202), CRuby's String hash, under a random
    key drawn once per process. Their #hash values differ from 4.0.5's. Short Strings are
    unchanged.
  • Core methods read an Array the way CRuby does (#216, #228). sum, take_while,
    drop_while, to_h, uniq { }, dig and the pattern forms of any? and the other
    predicates no longer call an Array subclass's own #each, #size or #[]. Range#sum
    of Integers ignores a redefined Integer#+ (#229).

Downloads and packaging

  • The startup library ships on every platform (#201). IronRuby.Startup.dll, the
    prelude, RubyGems and the common standard library compiled ahead of time, failed to build
    for every earlier release. All six archives now carry it, and an archive ships it only if
    it loads, gives the same output and starts faster. On the CI runners, ir -e 1 on
    linux-x64 .NET 10 took 375 ms with it and 500 ms without (median of 5).

Known issues

  • In a method that has run often enough to be compiled (a few dozen calls), an error raised
    by C# code inside a rescue clause or rescue modifier still has a nil cause (#204).
    4.0.5 gave nil in every case. raise in the clause and ensure clauses are right.
  • Three ruby/spec examples fail when the specs do not run as root: Kernel#load and
    Kernel#require with an unreadable file, and Dir.delete without permission.
  • IO.for_fd(2) without a mode opens the descriptor read-only, and 42.compare_to(1)
    answers where CRuby raises NoMethodError (#216, #218).

For contributors

  • Library initializers are written by a source generator during the build (#217). A new
    or changed [RubyMethod] needs only a build; Initializers.Generated.cs is gone.
  • Speed work has its tools in Util/perf (#215, #221, #230, #232): steady-state AWFY
    (awfy.rb), per-operation costs (micro.rb), A/B of two builds (ab.rb, and ab.rb -i
    for instructions per call), a census of what the method JIT and light frames make of every
    def without running it (census.rb), and LEDGER.md with the numbers and what was tried.
    IR_LIGHT_FRAMES=why says why a method keeps its scope. Differential matrices under
    Util/ compare IronRuby with CRuby (#222, #224).
  • Two method JIT prototypes, off by default (#219, #220): -X:JITMethods (needs
    -p:IronRubyJitEmit=true) and -X:JITCalls. Docs/jit-resume-deopt.md is a design for
    a deopt that does not restart the method (#223).
  • CI builds and tests the WebAssembly host on every push (wasm.yml, #211), and a
    nightly job sweeps all five ruby/spec suites (spec-sweep.yml, #212).
  • A new DLR patch, 0108 (#208). Apply it to existing DLR checkouts.

Download

Self-contained: unpack one and run ./ironruby, ./iirb.sh and ./igem.sh - on Windows
ironruby.cmd, iirb.cmd and igem.cmd. No .NET to install. Or, on Windows, run the
installer.

On .NET 10 (LTS, the default):

  • Windows x64 installer: ironruby-4.0.6-win-x64-setup.exe, the zip below, installed
    into C:\IronRuby40-x64 and put on the PATH
  • Windows x64: ironruby-4.0.6-win-x64.zip, with Windows Forms, WPF, ironrubyw.exe
    and Samples\Notepad\notepad.cmd
  • Linux x64: ironruby-4.0.6-linux-x64.tar.gz
  • macOS arm64: ironruby-4.0.6-osx-arm64.tar.gz, built in CI, not tested there

On .NET 11:

  • Windows x64: ironruby-4.0.6-net11-win-x64.zip, with the same contents as the
    .NET 10 zip
  • Linux x64: ironruby-4.0.6-net11-linux-x64.tar.gz
  • macOS arm64: ironruby-4.0.6-net11-osx-arm64.tar.gz, built in CI, not tested there

SHA256SUMS lists the checksums of all of them. Each file and SHA256SUMS has a signed
build provenance attestation, which says which workflow built it, from which commit, in
which run:

gh attestation verify ironruby-4.0.6-net11-linux-x64.tar.gz --repo Largo/ironruby

What's Changed

  • Integer.sqrt: Karatsuba square root; String#hash: SipHash-1-3 for long ASCII strings by @Largo in #202
  • Exception correctness: $! after an ensure that jumps, causes of C#-raised errors, refined === in rescue, backtrace frames and lines by @Largo in #204
  • Thread#kill no longer lost while a fiber's resumer is still spinning; String#split at / /x as CRuby by @Largo in #203
  • Release archives: ship the startup library on every platform (CS0006 fix, arm64 JIT fault) by @Largo in #201
  • macOS: IO.pipe, IO.popen and backquotes without pipe2; variadic fcntl/open on Apple arm64 by @Largo in #205
  • Numerics (#89): Integer()/Float() keyword fast path, Bignum bit slices, String#to_c scanner by @Largo in #206
  • Strings: long ASCII String#+ held as bytes; a slice that is appended to is copied once by @Largo in #207
  • Thread.new: let finished threads be collected (DLR ThreadLocal, Thread.list registry) by @Largo in #208
  • Thread#raise and fibers: no stale wake-up after a raise, no half-done switch bookkeeping by @Largo in #209
  • raise: no stack trace until the backtrace is needed, also through ensure (#89) by @Largo in #210
  • Cheaper blocks, keywords and Enumerator#next; CRuby test/ruby fixes; nightly spec sweep by @Largo in #212
  • IronRuby in the browser: merge wasm/ into master, with CI by @Largo in #211
  • Rounds seven to ten: all thirteen AWFY benchmarks measured; List 41%, CD 35%, NBody 34% and Permute 10% faster by @Largo in #216
  • Faster calls, blocks and instance variables: 1.86x to 1.05x of CRuby on five AWFY benchmarks by @Largo in #215
  • Library initializers are written by a source generator during the build by @Largo in #217
  • Beyond AWFY: ten areas measured against CRuby; erubi 94x→3.1x, rubocop 60x→32x, nqueens and structaref past CRuby by @Largo in #218
  • Method JIT prototypes: bodies as assembly methods (-X:JITMethods) and direct calls between compiled methods (-X:JITCalls), both off by default by @Largo in #219
  • JIT benchmark runner: usable CPU default, stop at a failed reference run; write-up wording (review of #219) by @Largo in #220
  • What TruffleRuby keeps in Ruby: a study, and three entry-cost fixes for Ruby-written core methods by @Largo in #221
  • jit-matrix.rb: every effect before every deopt source, in four orders by @Largo in #222
  • Ledger: what keeps CD's tree_insert out of the method JIT, and a construct-then-deopt matrix by @Largo in #224
  • Ruby C API: load C extensions on Linux and Windows; build gems' extensions (sqlite3) by @Largo in #226
  • Design: a JIT deopt that does not restart the body (gap 1) by @Largo in #223
  • Array#each_index as a block-loop kind (gap 2) by @Largo in #225
  • perf ledger: the interpreted-delegate hop was removed once, and it bought nothing by @Largo in #227
  • Ten prelude core methods faster, from the /perf-core loop by @Largo in #228
  • sum from a Float initial value follows CRuby 4.0 (Array, Enumerable, Range, Hash) by @Largo in #229
  • ab.rb -i: instructions per call for A/B on a busy machine; one gate per branch after a quick check by @Largo in #230
  • Light frames take a call that passes the method's block on by @Largo in #231
  • A census of JIT and light-frame coverage without running code, and perf-step judged by it by @Largo in #232
  • Light frames take a call that passes a splatted value on by @Largo in #233
  • Light frames take a method that interpolates by @Largo in #234
  • Release archives ship the C API's libironruby-capi by @Largo in #236
  • Release 4.0.6 by @Largo in #235
  • 4.0.6 notes and README: the Linux and Windows downloads carry the C API by @Largo in #237

Full Changelog: v4.0.5...v4.0.6