Skip to content
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

Emit a performance warning when OpenStruct is used #56

Merged
merged 1 commit into from
Sep 29, 2023

Conversation

casperisfine
Copy link
Contributor

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

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.
@marcandre
Copy link
Member

Sounds great to me 👍

@byroot
Copy link
Member

byroot commented Sep 29, 2023

@marcandre no objections to me merging myself?

@marcandre
Copy link
Member

None, I was just waiting to see if there was any other feedback :-) Thanks!

@byroot byroot merged commit 5826e12 into ruby:master Sep 29, 2023
16 checks passed
@byroot
Copy link
Member

byroot commented Sep 29, 2023

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants