Skip to content

Bug: %m in default IRB prompt can make the console unusably slow for objects with huge to_s/inspect #1126

Description

@jvlara

Versions

irb: 1.15.2
debug: 1.11.0
Ruby: 3.3.6
OS: MacOS

Summary

Using IRB’s default prompt:

{
  PROMPT_I: "%N(%m):%03n> ",
  PROMPT_S: "%N(%m):%03n%l ",
  PROMPT_C: "%N(%m):%03n* ",
  RETURN:   "=> %s\n"
}

the %m expansion becomes extremely slow when the current context’s to_s/inspect is very large. In a real app with a “massive” object (its string representation is YAML-like and huge), every prompt render freezes for a long time.

Why this happens

%m appears to derive its text from the current context receiver (ultimately calling to_s/inspect). If that method returns a very large string, printing it each prompt render overwhelms the console and makes IRB feel hung.

Expected behavior

The default prompt should remain responsive even if self#to_s or self#inspect are slow or produce large output.

Minimal reproduction

This script simulates a large to_s:

# script.rb
require "irb"

class Liquidation
  def dummy_method
    binding.irb
  end

  def to_s
    "VeryLongClass\n" * 100_000_000 # large string
  end
end

Liquidation.new.dummy_method

or, if you prefer the debug console:
bundle exec ruby script.rb

You’ll notice the prompt becomes immediately sluggish, as %m tries to print the gigantic to_s on every render.

Video:

Screen.Recording.2025-10-17.at.11.35.21.mov

Workarounds

Avoid %m in the prompt:

IRB.conf[:PROMPT][:FAST] = {
  PROMPT_I: "%N:%03n> ",
  PROMPT_S: "%N:%03n%l ",
  PROMPT_C: "%N:%03n* ",
  RETURN:   "=> %s\n"
}
IRB.conf[:PROMPT_MODE] = :FAST

Proposal

Consider changing the default %m behavior to a cheap, bounded representation, for example:

If self is a Module/Class: self.name (or fallback to self.class.name)

Otherwise: self.class.name#object_id

That keeps the default prompt fast while still being informative.

Notes / Real-world context

In our application, the default prompt tries to render a massive YAML-like string for the current context, which makes the console “go crazy slow.” A screenshot for reference:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions