Project

General

Profile

Actions

Feature #15836

closed

[Proposal] Make Module#name and Symbol#to_s return their internal fstrings

Added by byroot (Jean Boussier) almost 5 years ago. Updated almost 5 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:92585]

Description

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_literalAFAIK 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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0