-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Push debugger activation to first breakpoint hit instead of require "debug"
#797
Comments
Let me think some more time about it. |
With `RUBY_DEBUG_LAZY=1`, `require 'debug'` doesn't start a session but start when `debugger` method is called (or `require 'debug/start'` is called). This feature is experimental. #797
Your proposal is based on that: user only specify the breakpoint with
BTW requiring I introduced
fixed on #823
I'd supported it (override by requiring |
If users want to set breakpoints with other ways, say with I'm not sure why lazily loading debugger will reduce the possibilities to set breakpoints. Can you elaborate more?
Yes I also believe that's the way to go. But I'm not sure how much the effort it'd take and how it'd be prioritised. I think lazy-activation to reduce friction is a good first step toward that goal though. And once we made activation lightweight, we can turn it back on and users wouldn't notice a thing.
I can test if disabling the TracePoint reduce test failures in our apps.
I think the features you listed are useful, but also seem quite specialised. In my experience using and helping my colleagues use the debugger in apps and gems, we rarely need them. I'm not saying that we represent most users, but it may be a shared experience. So how about we do it in another way:
The idea is, to make the debugger easily accessible to average users, we make it as lightweight as possible by default (lazy-activation is one way). And if some users want more powerful features, we also give them options to change the default behaviour. WDYT?
I think that's a good idea too 👍 Thank you so much for these fixes 🙏 |
With `RUBY_DEBUG_LAZY=1`, `require 'debug'` doesn't start a session but start when `debugger` method is called (or `require 'debug/start'` is called). This feature is experimental. #797
For example,
I believe reducing functionality is for high-level users who can understand what they are doing. |
for example: "if you want to use Regexp on Ruby, please use |
I think it really depends on what functionalities we are reducing and what are most users's usage of them. For example, I haven't needed to use In the contrary, at Shopify we several applications, as well as gems like Tapioca, can benefit from having lazy-activation by default. (Also the app of my prev company, which's tests fail whenever I also want to add an update on the I experimented
And the initial CI seemed to run fine, so we merged the PR. But it turned out it randomly hanged some of the CI suites from time to time. And it took us a few days to pin down to my change. We don't exactly know what code was causing that, but it's loading the debugger that caused it. So we now added It's possible that we can add What I want to say is, we're not requesting any advanced features of the debugger. We simply want to add The |
So |
Sorry I wasn't clear on this: the problem was caused by some CI tests not having
So my point is, needing to manually apply |
BTW why do you use debug.gem on CI? |
In Rails applications, debug gems usually will be put under the group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end So when running tests, the |
So you mean that
So the gem "debug.gem" is not assumed that "require it when debug with it" but introduce |
Sorry for the delay.
Yes that's the feedback I got from many devs, also my personal expectation. I understand that the goal is But at the moment and in near future,
Therefore, making its activation behaviour similar to other gems (e.g. |
At least I don't think such goal. |
I think if you want to make |
Given that I guess the main use case for When people add |
OTOH using |
I also recently compared how the eager and lazy activation options would affect Rails application's test duration on CI, by using different gem declaration in Gemfile:
I ran full test suites of 3 different Rails apps, and saw between I think it's understandable that having a debugger running alongside the application would increase its memory consumption and cause extra overhead. But to me it means the debugger should by default either not be activated, or avoid the activities that would introduce such negative impacts. And during a conversation with @ko1, he suggested that the overhead I observed may be caused by this line, which my later testings seemed to confirm as the 9~11% overhead largely disappeared. But I didn't do as thorough testing due to short of time, so we may need to verify that with more testings. Notes
|
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.
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.
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.
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.
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.
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.
Proposal
require "debug"
won't activate the debugger. Debugger will only be activated when the first breakpoint is triggered.require "debug"
will be the same asrequire "debug/prelude"
require "debug/open"
andrequire "debug/open_nonstop"
's behaviour will remain the same.Why
Side-effects
In apps that have
Bundler.require
, like most Rails apps, havinggem "debug"
in Gemfile means thedebug
gem is always activated when the app is booted.However, with the debugger's activation, many things will happen in the background:
TracePoint
s would be enabled (example)To most apps, having them in the background doesn't make a huge difference. But to some, having the debugger activated causes tests to fail.
For example, I tested 5 mid-to-large Rails apps in Shopify, and 3 of them have test failures that only happen when
debug
is activated:File.readlines
and could break when this line is triggered in the background.NoMethodError
exceptions that only happens with the debugger activated.Therefore, we always have
require: false
aftergem "debug"
.Problem Solved?
However, having
require: false
means users need to manually typerequire "debug"
before start debugging with console. But in the meantime,byebug
can be required by default without the same side-effects. Sobyebug
doesn't need that manual require.This extra require step is quite inconvenient for people considering switching from
byebug
todebug
.Other Smaller Issues
require "debug"
locks the UI to console, so if users want to use the remote UI by requiringdebug/open
after the app is booted,require: false
is also needed.Possible Change
The text was updated successfully, but these errors were encountered: