From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id D08D81F45F for ; Tue, 7 May 2019 16:47:44 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 454DC120AA1; Wed, 8 May 2019 01:47:38 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 1DA72120AAA for ; Wed, 8 May 2019 01:47:34 +0900 (JST) Received: by filter0042p3iad2.sendgrid.net with SMTP id filter0042p3iad2-17009-5CD1B6A7-1F 2019-05-07 16:47:35.487990031 +0000 UTC m=+68658.208475693 Received: from herokuapp.com (unknown [34.228.113.206]) by ismtpd0025p1mdw1.sendgrid.net (SG) with ESMTP id j4QL1R1iTyCxJ8RPH5vShQ for ; Tue, 07 May 2019 16:47:35.425 +0000 (UTC) Date: Tue, 07 May 2019 16:47:35 +0000 (UTC) From: shevegen@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 68073 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15836 X-Redmine-Issue-Author: byroot X-Redmine-Sender: shevegen X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?6lbdtOg4RDRLuxD00eQtQKgoNAsge5d4xND7cbMQd0xv0ReynB4ijFQ5Lvl8Xw?= =?us-ascii?Q?K3RvtZb+6bGgbMQF4VvW1RbyhGsUl1Y=2Ff0jwFVc?= =?us-ascii?Q?5HxHr+Be4CJkImtcn1TO1Af456OJcHaMAxWjVex?= =?us-ascii?Q?W5uq387PglqnqF02xAQnPnoJAIpmqPQjkb6wIM1?= =?us-ascii?Q?cTthinCsPYb6rnH0i7h9fJMpKcvYUdktbBg=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 92590 Subject: [ruby-core:92590] [Ruby trunk Feature#15836] [Proposal] Make Module#name and Symbol#to_s return their internal fstrings X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #15836 has been updated by shevegen (Robert A. Heiler). > frozen_string_literalAFAIK should become the default some day Matz said that but it will not be for ruby 3.0 at the least. In my own code bases I am using frozen strings a lot, through the shebang; either "# frozen_string_literal: false" (initially) but these days more and more "# frozen_string_literal: true". I think other ruby users may be able to transition into frozen strings if enough time is given AND recommendations are given from the ruby core team in due time whenever there are (future) changes. > string used as hash keys are now automatically interned as well. Although the use case for HashWithIndifferentAccess (I hate how long that name is ...) is probably not completely void, with strings being frozen it appears to me as if one use case (the speed factor) is nullified. There may be still other use cases probably, such as API design e. g. when people have to make a decision between "do I have to use a String or a Symbol here". Personally I like both strings and symbols, though; I think jeremy evans once gave a good explanation or wrote documentation to emphasis the distinction in the official doc (but I may misremember). ---------------------------------------- Feature #15836: [Proposal] Make Module#name and Symbol#to_s return their internal fstrings https://bugs.ruby-lang.org/issues/15836#change-77951 * 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/