Actions
Misc #20222
closedDedup-ing clarification
Status:
Closed
Assignee:
-
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?
Updated by alanwu (Alan Wu) 9 months ago
Seems like a valid optimization to me and is similar to identity of small integers versus heap allocated bignums.
Updated by byroot (Jean Boussier) 9 months ago
- Related to Feature #8992: Use String#freeze and compiler tricks to replace "str"f suffix added
Updated by byroot (Jean Boussier) 9 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) 9 months ago
- Status changed from Open to Closed
Thank you! This helps explain it.
Actions
Like0
Like0Like0Like0Like0