Project

General

Profile

Actions

Misc #20222

closed

Dedup-ing clarification

Misc #20222: Dedup-ing clarification

Added by kddnewton (Kevin Newton) almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Assignee:
-
[ruby-core:116482]

Description

source = %q{"foo".freeze.equal?("foo".freeze)} RubyVM::InstructionSequence.compile(source).eval # => true RubyVM::InstructionSequence.compile_option = false RubyVM::InstructionSequence.compile(source).eval # => false 

"foo".freeze uses opt_str_freeze when optimizations are turned on, which also deduplicates. This means this code has different behavior depending on if optimizations are turned on or off.

To be clear, I'm not saying whether or not this is a problem. I'm asking if this is desired behavior?


Related issues 1 (0 open1 closed)

Updated by alanwu (Alan Wu) almost 2 years ago Actions #1 [ruby-core:116625]

Seems like a valid optimization to me and is similar to identity of small integers versus heap allocated bignums.

Updated by byroot (Jean Boussier) almost 2 years ago Actions #2

  • Related to Feature #8992: Use String#freeze and compiler tricks to replace "str"f suffix added

Updated by byroot (Jean Boussier) almost 2 years ago Actions #3 [ruby-core:116645]

For the full context see [Feature #8992].

It's true that it's a bit questionable that it's treated as an optimization, but realistically speaking no-one is compiling code without optimizations, it's just for MRI developers.

Also erubi and a few other projects heavily rely on this for performance.

Updated by kddnewton (Kevin Newton) almost 2 years ago Actions #4 [ruby-core:116654]

  • Status changed from Open to Closed

Thank you! This helps explain it.

Actions

Also available in: PDF Atom