-
Notifications
You must be signed in to change notification settings - Fork 22.2k
Allow entirely opting out of deprecation warnings #42913
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
Author
|
Here is a benchmark: require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", branch: "main"
gem "benchmark-ips"
end
require "active_support"
class MainBranch < ActiveSupport::Deprecation
end
class WithThisPR < ActiveSupport::Deprecation
def initialize(*)
super
self.silenced = true
end
end
WithThisPR.behavior = :silence
MainBranch.behavior = :silence
Benchmark.ips do |x|
x.report("entirely silenced with this PR") { WithThisPR.warn("foo") }
x.report("behavior = :silence on main branch") { MainBranch.warn("foo") }
x.compare!
end |
Member
|
Instead of introducing a new option, can we should change the behavior of the value |
Member
|
Ah, but there is also the |
9d346da to
fb24aad
Compare
ghiculescu
commented
Jul 29, 2021
ghiculescu
commented
Jul 29, 2021
Previously if you did `app.config.active_support.deprecation = :silence`, some work would still be done on each call to `ActiveSupport::Deprecation.warn`. Specifically [checking the backtrace](https://github.com/rails/rails/blob/12372c54828e2ac04b230cedd5cbb75181e62d29/activesupport/lib/active_support/deprecation/reporting.rb#L21), generating the [deprecation warning](https://github.com/rails/rails/blob/12372c54828e2ac04b230cedd5cbb75181e62d29/activesupport/lib/active_support/deprecation/reporting.rb#L22), and [checking if the warning is disallowed](https://github.com/rails/rails/blob/12372c54828e2ac04b230cedd5cbb75181e62d29/activesupport/lib/active_support/deprecation/reporting.rb#L23). In very hot paths, this could cause performance issues. This PR lets you turn off deprecation reporting entirely for a specific environment. ```ruby config.active_support.report_deprecations = false ``` ^ so has the same outcome as: ```ruby config.active_support.deprecation = :silence config.active_support.disallowed_deprecation = :silence ``` But it will short circuit [here](https://github.com/rails/rails/blob/12372c54828e2ac04b230cedd5cbb75181e62d29/activesupport/lib/active_support/deprecation/reporting.rb#L19).
fb24aad to
ea3185e
Compare
3zrv
approved these changes
Jul 31, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously if you did
app.config.active_support.deprecation = :silence, some work would still be done on each call toActiveSupport::Deprecation.warn. Specifically checking the backtrace, generating the deprecation warning, and checking if the warning is disallowed.In very hot paths, this could cause performance issues. This PR lets you turn off deprecation reporting entirely for a specific environment.
^ has the same outcome as:
But it will short circuit here.