[ruby-core:102333] Re: eliminating symbols...
From:
Benoit Daloze <eregontp@...>
Date:
2021-01-31 14:40:50 UTC
List:
ruby-core #102333
I believe Symbols have a significant performance advantages compared to regular String, i.e., they can always be compared by identity. However, if a String would know if it's "interned" in the fstring table, then such optimization could be done for fstring Strings too (if both operands are fstring Strings). IMHO, learning the difference between String and Symbol is part of learning Ruby. Symbol are identifiers or enums, String is basically just data. On Sun, Jan 31, 2021 at 2:13 AM Eric Wong <normalperson@yhbt.net> wrote: > Was just catching up with some of the HashWithIndifferentAccess discussion > at > https://bugs.ruby-lang.org/issues/17472 > > Could a magic comment (e.g. "# symbols_are_strings: true") > make :foo a shorthand for a frozen 'foo' String? > > If you turn your head sideways, the : character can look like '' > > That would provide a migration path which would allow reducing > the use of Symbols and maybe get rid of it down-the-line(*). > > Implementation-wise, every symbol already has a frozen string > associated with it, so there's no extra memory cost. > > > (*) I now consider Symbols a mistake of the Ruby language design > and they should've been only an implementation detail. This > is even more so with GC-able symbols nowadays. But maybe my > brain is infected by too much Perl5 :P > > Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> > <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core> > Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>