Project

General

Profile

Actions

Feature #20429

closed

Emit a performance warning when specially optimized core methods are redefined

Added by byroot (Jean Boussier) about 1 month ago. Updated 30 days ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:117523]

Description

MRI has a number of core methods with special handling in the interpreter and both JITs that if they are redefined negatively impact Ruby performance.

The methods currently are (I may be missing a few):

  • Integer: #+, #-, #*, #/, #%, #<, #>, #<=, #>=
  • Float: #+, #-, #*, #/, #<, #>, #<=, #>=
  • String: #freeze, #size, #length, #empty?, #+, #succ, #%, #-@
  • Array: #size, #length, #empty?, #hash
  • Hash: #size, #length, #empty?, #[], #[]=

Noticing that a dependency do redefine one of these methods can be non-trivial, so I'd like to emit a :performance warning when it happens.

I can't really think of much reasons to redefine these aside from fun hacks, so I believe discouraging it would be valuable.

Patch: https://github.com/ruby/ruby/pull/10532

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0