Skip to content

Optimize math and bitwise operators for unknown types #9168

Description

@headius

Math and bitwise operations can be optimized to avoid a full dynamic dispatch when both sides are core numeric types and the operator has not been redefined.

There's a series of these optimizations in CRuby that have been expanded over time, starting here: https://github.com/ruby/ruby/blob/63b082cf0e87942dcea28cbdeb1c8a9e616e903a/vm_insnhelper.c#L6710

We currently do a similar optimization when the RHS is a literal numeric type, via the MathLinker class for invokedynamic and the operator CallSite subclasses for non-indy, but we should explore the value of doing so when the RHS is not a literal value.

Given that we already can inline through such calls using indy, there may be little to gain from adding additional override checks and static calls, but the extent of these optimizations in CRuby makes me want to give it a try.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions