Emit a performance warning when OpenStruct is used#56
Merged
byroot merged 1 commit intoruby:masterfrom Sep 29, 2023
Merged
Conversation
The OpenStruct documentation clearly state that it shouldn't be used when performance is expected. Ruby 3.3 introduce a new category of warnings that is silenced by default: performance. The expected use case is to enable this warning when looking for potential performance issues within an application. As such I think it would make sense to emit a performance warning when OpenStruct is used, as it may help pinpoint that a dependency rely on it, etc.
Member
|
Sounds great to me 👍 |
Member
|
@marcandre no objections to me merging myself? |
Member
|
None, I was just waiting to see if there was any other feedback :-) Thanks! |
Member
|
Thanks to you! |
matzbot
pushed a commit
to ruby/ruby
that referenced
this pull request
Sep 29, 2023
(ruby/ostruct#56) The OpenStruct documentation clearly state that it shouldn't be used when performance is expected. Ruby 3.3 introduce a new category of warnings that is silenced by default: performance. The expected use case is to enable this warning when looking for potential performance issues within an application. As such I think it would make sense to emit a performance warning when OpenStruct is used, as it may help pinpoint that a dependency rely on it, etc. ruby/ostruct@5826e12db8 Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
dhh
pushed a commit
to rails/jbuilder
that referenced
this pull request
Apr 29, 2024
This commit uses OpenStruct only if available because of the following reasons: - Starting from Ruby 3.4.0dev, Using `ostruct` raises the following warning. > ostruct was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0. Add ostruct to your Gemfile or gemspec. - And when the warning category is `:performance` it also raises this warning. > "OpenStruct use is discouraged for performance reasons Refer to https://bugs.ruby-lang.org/issues/20309 ruby/ruby#10428 ruby/ostruct#56 Fix #561
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
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.
The OpenStruct documentation clearly state that it shouldn't be used when performance is expected.
Ruby 3.3 introduce a new category of warnings that is silenced by default: performance.
The expected use case is to enable this warning when looking for potential performance issues within an application.
As such I think it would make sense to emit a performance warning when OpenStruct is used, as it may help pinpoint that a dependency rely on it, etc.
cc @tenderlove @jhawthorn @marcandre