You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.rbrequire"irb"classLiquidationdefdummy_methodbinding.irbenddefto_s"VeryLongClass\n" * 100_000_000# large stringendendLiquidation.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.
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:
Versions
irb: 1.15.2
debug: 1.11.0
Ruby: 3.3.6
OS: MacOS
Summary
Using IRB’s default prompt:
the
%mexpansion 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:
or, if you prefer the debug console:
bundle exec ruby script.rbYou’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:
Proposal
Consider changing the default %m behavior to a cheap, bounded representation, for example:
If self is a Module/Class:
self.name(or fallback toself.class.name)Otherwise:
self.class.name#object_idThat 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: