Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Module#name and Symbol#to_s return their internal fstrings #2175

Open
wants to merge 1 commit into
base: trunk
from

Conversation

1 participant
@byroot
Copy link
Contributor

commented May 7, 2019

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.