Skip to content

Commit 7254549

Browse files
committed
Add require: "debug/prelude" after debug's Gemfile entry
In ruby/debug#797, we found that requiring `debug` automatically activates it, which could introduce runtime overhead and cause memory bloat. And I think many users aren't aware of this and could be taxed by this unnecessarily (e.g. having longer builds on CI). Therefore, I propose to add `require: "debug/prelude"` after `debug`'s Gemfile entry in the default Gemfile template. This way, users can still use breakpoint methods like `debugger`, `binding.break`, and `binding.b`, but the debugger won't be activated until a breakpoint is hit.
1 parent 6a38d3a commit 7254549

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

railties/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
* Generated Gemfile will include `require: "debug/prelude"` for the `debug` gem
2+
3+
Requiring `debug` gem directly automatically activates it, which could introduce
4+
additional overhead and memory usage even without entering a debugging session.
5+
6+
By making Bundler require `debug/prelude` instead, developers can keep their access
7+
to breakpoint methods like `debugger` or `binding.break`, but the debugger won't be
8+
activated until a breakpoint is hit.
9+
10+
*Stan Lo*
11+
112
* Allow Actionable Errors encountered when running tests to be retried.
213

314
```txt

railties/lib/rails/generators/rails/app/templates/Gemfile.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ gem "bootsnap", require: false
3333

3434
group :development, :test do
3535
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
36-
gem "debug", platforms: %i[ mri <%= bundler_windows_platforms %> ]
36+
gem "debug", platforms: %i[ mri <%= bundler_windows_platforms %> ], require: "debug/prelude"
3737
<%- unless options.skip_brakeman? -%>
3838

3939
# Static analysis for security vulnerabilities [https://brakemanscanner.org/]

0 commit comments

Comments
 (0)