Project

General

Profile

Actions

Misc #20814

closed

iseq optimizations on constant condition

Added by hurricup (Alexandr Evstigneev) 28 days ago. Updated 24 days ago.

Status:
Feedback
Assignee:
-
[ruby-core:119613]

Description

ruby 3.4-preview2 seems optimizes out some stuff when building iseq and this may lead to user unexpected behavior when debugging, because some lines just optimized out.

Example:

def foo1
  if true
    nil
  else
    1
  end
end

produces:

== disasm: #<ISeq:foo1@/test.rb:1 (1,0)-(7,3)>
0000 putnil                                                           (   3)[LiCa]
0001 leave                                                            (   7)[Re]

Two questions:

  • is there way to disable such optimizations?
  • are there some specs on things that can be optimized.

Updated by nobu (Nobuyoshi Nakada) 28 days ago

  • Status changed from Open to Feedback

Because of the dynamic feature of Ruby, the optimization on ISeq is very limited.
For instance, elimination of unreachable branch because of a simple always-true/false condition expression, in your example.

  • is there way to disable such optimizations?

To disable optimizations, see the document of RubyVM::InstructionSequence.compile_option=.
https://docs.ruby-lang.org/en/master/RubyVM/InstructionSequence.html#method-c-compile_option-3D

  • are there some specs on things that can be optimized.

We do not provide explicit documentation or specifications regarding optimizations because they are internal features and may change without notice.

Updated by nobu (Nobuyoshi Nakada) 28 days ago ยท Edited

  • Description updated (diff)

Updated by hurricup (Alexandr Evstigneev) 24 days ago

nobu (Nobuyoshi Nakada) wrote in #note-1:

To disable optimizations, see the document of RubyVM::InstructionSequence.compile_option=.
https://docs.ruby-lang.org/en/master/RubyVM/InstructionSequence.html#method-c-compile_option-3D

My question is more about the runtime. E.g I want to run a ruby program with optimizations disabled at all. Or load using rb_load/rb_load_protect while ruby process is already alive with default settings.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0