Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Box on Rails (not yet)

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

Box on Rails (not yet)

The presentation in RubyKaigi 2026 follow up

Avatar for Satoshi Tagomori

Satoshi Tagomori

September 05, 2026

More Decks by Satoshi Tagomori

Other Decks in Technology

Transcript

  1. 田籠 聡 (Satoshi Tagomori) @tagomoris SAKURA internet (2024.08〜) Cloud Business

    Strategy Division Maintainer/Founder: OSS: Ruby, Fluentd, MessagePack, Norikra, Woothee, … Event: ISUCON Service: Pathtraq
  2. Types of Ruby Box on Ruby 4.0 Box#root? Root Box

    TRUE Box#main? FALSE For method of built-in classes/modules (including RubyGems, etc) Main Box FALSE TRUE Default box, for the main .rb script (and les loaded from the main) Optional Box FALSE FALSE The boxes created by Ruby::Box.new fi User Box
  3. Box Timeline in Ruby Process Process start Main start Root

    Box Box.new Box.new Root Box Main Box Box #3 Box #4
  4. Box Timeline in Ruby Process Process start Main start Box.new

    Box.new Root Box Root Box Main Box Copy from the root box Box #3 Copy from the root box Box #4 Copy from the root box
  5. Mutable Root Box: Required in Root Process start Main start

    Box.new Box.new require ʻjsonʼ Root Box Root Box JSON Main Box Copy from the root box Box #3 Copy from the root box JSON Box #4 Copy from the root box ff The mutable root box makes di erence between boxes
  6. Mutable Root Box: States in Root Process start Main start

    Root Box require ʻrubygemsʼ Gem Box.new Gem Box.new Gem YAML Root Box Main Box require ʻyamlʼ Box #3 require ʻyamlʼ Box #4 Gem has states as class instance variables (e.g., @loaded_specs), and it causes inconsistencies
  7. Problems of Mutable Root in 4.0 Root: Source of copies,

    Box to run built-ins • Source of box copies • Should be immutable • Should NOT run any code (after main starts) • Separated mutable states • Should be loaded per-box
  8. Types of Ruby Box on Ruby master (and 4.0.7/4.1 or

    later) Box#master? Box#root? Box#main? Master Box Root Box TRUE FALSE FALSE TRUE FALSE The master copy of boxes FALSE For methods of built-in classes/ modules Main Box FALSE FALSE TRUE Default box, for the main .rb script (and les loaded from the main) Optional Box FALSE FALSE FALSE The boxes created by Ruby::Box.new fi User Box
  9. Updated Timeline in Ruby Process Process start Main start Box.new

    Box.new Master Box Master Box require ʻjsonʼ Root Box JSON Copy from the root box Main Box Copy from the root box Box #3 Box as master-copy and to run built-ins are separated! Master box never run any code after main starts Copy from the root box Box #4 Copy from the root box
  10. Mutables Separated Per Box Process start Main start Box.new Box.new

    Master Box Master Box require ʻrubygemsʼ Gem Copy from the root box require ʻrubygemsʼ Gem Root Box Main Box Copy from the root box require ʻrubygemsʼ Gem Box #3 Copy from the root box Every boxes have their own RubyGems (Gems are not built-in now) require ʻrubygemsʼ Gem Box #4 Copy from the root box
  11. Works for RoR in Boxes #1 by tagomoris • The

    separation of the master box • “[Box] Fix about wrong method invalidation - #17119” https://github.com/ruby/ruby/pull/17119
  12. Works for RoR in Boxes #2 by hsbt • “[Bug

    #22123] Do not consume BUNDLER̲SETUP outside the main box - #18218” https://github.com/ruby/ruby/pull/18218 • “Fix gemspec evaluation under Ruby::Box - #9809” https://github.com/ruby/rubygems/pull/9809 • “Make the gem CLI work under RUBY̲BOX=1 - #9810” https://github.com/ruby/rubygems/pull/9810 • “Defer unloading box-local extension DLLs on Windows - #18509” https://github.com/ruby/ruby/pull/18509' • “Fix autoload's require dispatch under Ruby::Box - #18534” https://github.com/ruby/ruby/pull/18534 • “Fix prepend ancestry order in user boxes - #18535” https://github.com/ruby/ruby/pull/18535 • “Copy box-local extensions into a process-private directory - #18536” https://github.com/ruby/ruby/pull/18536
  13. Works for RoR in Boxes #3 by niku and hsbt

    • “Ensure Symbol#to̲proc respects caller's Ruby::Box context - #16865” https://github.com/ruby/ruby/pull/16865 • “Make Symbol#to̲proc respect the caller's box context for user boxes - #18546” https://github.com/ruby/ruby/pull/18546 • “Fix Box resolution crash with IFUNC frames - #16890” https://github.com/ruby/ruby/pull/16890 • “Fix Box resolution crashes with IFUNC frames - #18575” https://github.com/ruby/ruby/pull/18575
  14. Works for RoR in Boxes #4 by hsb • “[Bug

    #22090] Resolve classes in the caller's box in Marshal.load #18544” https://github.com/ruby/ruby/pull/18544 Introduces Primitive.attr! :caller_box to run Ruby code in the master box with the caller box as its context. (This idea is still in discussion)
  15. in Ruby30th 2025-12-30 Testing in boxes Don t you need

    a funky monkey patches in tests? • Applications tests sometimes need monkey patches • to mock library behaviors, IO objects, … • Most of tests can run without box. Just some of them can t. Ruby Process Application Code Test Runner Test Case Test Case Test Case • How about running tests in boxes? • Running all tests in boxes is too expensive Monkey Patches Test Case Ruby Box ’ ’ • Run just some of them in boxes!
  16. Works for Tests in Boxes by tagomoris • “Run .box.rb

    su x test cases in Ruby Box - #382” https://github.com/test-unit/test-unit/pull/382 Loads test code of les like *.box.rb in separated boxes! Merged, and will be released in the next test-unit version (Available with Ruby 4.1 or later) fi ffi • RSpec? Rake::TestTask?