Project

General

Profile

Actions

Misc #20222

closed

Dedup-ing clarification

Added by kddnewton (Kevin Newton) 10 months ago. Updated 10 months 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)

Related to Ruby master - Feature #8992: Use String#freeze and compiler tricks to replace "str"f suffixClosedmatz (Yukihiro Matsumoto)Actions

Updated by alanwu (Alan Wu) 10 months ago

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

Actions #2

Updated by byroot (Jean Boussier) 10 months ago

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

Updated by byroot (Jean Boussier) 10 months ago

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) 10 months ago

  • Status changed from Open to Closed

Thank you! This helps explain it.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0