Skip to content

Emit a performance warning when redefining specially optimized methods #10532

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 1 commit into from
Apr 15, 2024

Conversation

casperisfine
Copy link
Contributor

This makes it easier to notice a dependency is causing interpreter or JIT deoptimization.

Warning[:performance] = true

class String
  def freeze
    super
  end
end
./test.rb:4: warning: Redefining 'String#freeze' disable multiple interpreter and JIT optimizations

@byroot byroot requested review from ko1, eregon and k0kubun April 15, 2024 11:09
@eregon
Copy link
Member

eregon commented Apr 15, 2024

./test.rb:4: warning: Redefining 'String#freeze' disable multiple interpreter and JIT optimizations

I would suggest to replace multiple by <nothing> or several or some to avoid confusion.
On my first read I thought it disabled "multiple interpreter" (i.e. MVM) optimizations.
(but maybe I just read too fast too)

Also disable -> disables

@casperisfine
Copy link
Contributor Author

@eregon done.

This makes it easier to notice a dependency is causing interpreter or
JIT deoptimization.

```ruby
Warning[:performance] = true

class String
  def freeze
    super
  end
end
```

```
./test.rb:4: warning: Redefining 'String#freeze' disable multiple interpreter and JIT optimizations
```
@byroot byroot merged commit d019b3b into ruby:master Apr 15, 2024
@ko1
Copy link
Contributor

ko1 commented Apr 16, 2024

@byroot
I don't have strong opinion but could you make a ticket about it and NEWS entry?
I'll confirm it tomorrow's devmeeting by asking matz if the ticket is avaiable.

casperisfine pushed a commit to Shopify/ruby that referenced this pull request Apr 16, 2024
@casperisfine
Copy link
Contributor Author

could you make a ticket about it and NEWS entry?

Ah sorry, I went a bit too fast indeed. Here's the ticket and NEWS update:

https://bugs.ruby-lang.org/issues/20429

#10542

@ko1
Copy link
Contributor

ko1 commented Apr 16, 2024

Thank you!

@headius
Copy link
Contributor

headius commented Oct 14, 2024

These should not be tested as part of normal behavioral tests for these methods. This performance warning is specific to CRuby's way of optimizing and other implementations may not have the same limitation. Having these tests be done alongside normal behavioral testing means all implementations must warn for redefinition regardless of whether performance optimizations are affected.

These tests are also not a core behavior of any of these methods, and are a side effect of one implementation. They should be tested separately.

@eregon
Copy link
Member

eregon commented Oct 15, 2024

These are CRuby tests, it shouldn't be surprising they test CRuby-specific details.
It's good these new warnings are tested, and where else than test/ruby/test_optimization.rb which already has a list of such intrinsified methods?
It should be very easy for JRuby to define assert_performance_warning as no-op if it doesn't want to emit such warnings or test that there.

FWIW TruffleRuby has very similar warnings although for a slightly different set of methods:
https://github.com/oracle/truffleruby/blob/master/spec/truffle/redefining_optimized_core_methods_spec.rb

These tests are also not a core behavior of any of these methods, and are a side effect of one implementation. They should be tested separately.

The whole file actually only makes sense if these methods are intrinsified. Otherwise there would be no reason to test redefining more than one example method.
"separately" would mean duplicating the list, it seems obvious this is not desirable.

@headius
Copy link
Contributor

headius commented Oct 17, 2024

It should be very easy for JRuby to define assert_performance_warning

JRuby does not patch tests from MRI. We run them as is without modification and submit patches back when there are MRI specific expectations such as using RubyVM or testing for MRI specific behavior.

Is this warning now considered specified Ruby behavior? If so, should it not be tested in ruby/spec?

If it is not specified behavior, why is it tested alongside the ability to redefine these operators, which is specified behavior?

This test has been running in JRuby's test suite for many years. Adding this MRI-specific expectation caused it to start failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants