Feature #21951
openLazy load error enhancer gems to speed up boot time
Description
Summary¶
I investigate https://github.com/ruby/rubygems/issues/3799 for speed up Ruby's boot time. It depends on the environment, but when gems are included in GEM_HOME and user installation. I and Claude found that the most time-consuming part is requiring the three gems related to error notification, rather than loading the gemspec of default gems.
How it works¶
Defer loading of error_highlight, did_you_mean, and syntax_suggest from boot time to first error display. These gems only enhance Exception#detailed_message, so they are not needed until an error is actually displayed.
Performance¶
ruby -e1 boot time on Apple M1 Pro:
| Configuration | With user gems | Default gems only |
|---|---|---|
| master | 114.3 ms | 38.3 ms |
| This patch | 30.2 ms | 30.4 ms |
--disable-did_you_mean --disable-error_highlight --disable-syntax_suggest |
30.3 ms | 30.6 ms |
With this patch, ruby -e1 is as fast as disabling all three gems via flags. The error path has no measurable regression (+0.9 ms, within noise).
Patch¶
Updated by hsbt (Hiroshi SHIBATA) about 17 hours ago
- Tracker changed from Bug to Feature
- Backport deleted (
3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN)