Issue #15836 has been updated by byroot (Jean Boussier).


> Matz said that but it will not be for ruby 3.0 at the least.

I assumed it was due for 3.0, but good to know it isn't.

> I think other ruby users may be able to transition into frozen strings if enough time is given 

I contribute to many gems, and from what I can see `# frozen_string_literal: true` is extremely common. A good part is likely due to rubocop enforcing it, another is likely due to various article about how freezing strings made many codebases faster (sometimes oversold but that's another topic).

> with strings being frozen it appears to me as if one use case (the speed factor) is nullified

I'm not 100% sure I understood your point correctly. What I meant by hash keys being frozen is:

```
hash = {}
string = :foo.to_s # One string allocated here
hash[string] = true # A second string is allocated here because Hash apply: `-string.dup`
```

If `Symbol#to_s` was to return it's internal fstring, the above snippet would save 2 string allocations.

----------------------------------------
Feature #15836: [Proposal] Make Module#name and Symbol#to_s return their internal fstrings
https://bugs.ruby-lang.org/issues/15836#change-77953

* Author: byroot (Jean Boussier)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
# Why ?

In many codebases, especially Rails apps, these two methods are the source of quite a lot of object allocations.

`Module#name` is often accessed for various introspection features, autoloading etc.

`Symbol#to_s` is access a lot by HashWithIndifferentAccess other various APIs accepting both symbols and strings. 

Returning fstrings for both of these methods could significantly reduce allocations, as well as sligthly reduce retention as it would reduce some duplications.

Also, more and more Ruby APIs are now returning fstrings. `frozen_string_literal`AFAIK should become the default some day, string used as hash keys are now automatically interned as well.

### Backward compatibilty 

Of course this is not fully backward compatible, it's inevitable that some code in the wild is mutating the strings returned by these methods, but I do believe it's a rare occurence, and easy to fix. 

### Implementation

I implemented it here: https://github.com/ruby/ruby/pull/2175



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>