ruby/gem_prelude.rb
Hiroshi SHIBATA cadf8e7933 Lazy load error_highlight, did_you_mean, and syntax_suggest
[Feature #21951]

Defer loading these gems from boot to the first error display. They
only decorate Exception#detailed_message, so requiring them at boot is
unnecessary overhead. `ruby -e1` with user-installed gems drops from
114.3ms to 30.2ms on Apple M1 Pro, matching the --disable-* flags for
the three gems.

exc_detailed_message forces the autoload entries once on the first
call, only in the main Ractor, and then re-dispatches to pick up the
detailed_message decorators the gems prepend. When the first call
arrives through an already-prepended decorator, re-dispatching is
skipped to avoid decorating twice. The gems are loaded with the
C-level require so that displaying an error neither invokes nor
depends on Kernel#require monkeypatches.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 11:49:03 +09:00

10 lines
174 B
Ruby

begin
require 'rubygems'
rescue LoadError => e
raise unless e.path == 'rubygems'
warn "`RubyGems' were not loaded."
else
require 'bundled_gems'
end if defined?(Gem)