Daniel Ferreira <subtileos / gmail.com> wrote: > Hi, > > I would like to ask ruby core members the following question if it is possible: > > With the advent of Immutable Strings in ruby 3 what will be the > difference between Immutable Strings and Symbols? Note: we already have optimizations for immutable strings starting with Ruby 2.1+ Ruby 2.1 - introduced opt_str_freeze "literal string".freeze in source code dedupe, fine-grained, conservative, but verbose and ugly Ruby 2.2 - introduced opt_aset_with/opt_aref_with Hash#[] and Hash#[]= with literal string args have implicit freeze applied to them. This only affects base Hash objects and not subclasses; but is mostly transparent. Ruby 2.3 - frozen_string_literal magic comment supported per-source file. All literal strings in a source file with the magic comment can behave like "literal string".freeze from 2.1+ This needs to be carefully applied to existing source, as it is easy to introduce incompatibilities. For Ruby 3, I do not support frozen_string_literal becoming the default. I am 100% against breaking existing code. Too much 1.8 code was broken when 1.9 came out and Ruby lost users as a result. But it's not my decision... > Performance wise will Immutable Strings be similar to Symbols? Maybe, I haven't checked in a while. Sometimes, things can be faster since there's no intermediate (mutable) string object: `puts :foo` causes mutable "foo" to be created, but `puts "foo".freeze` will not. I was going to say Strings have better known hashing algorithms so you may get better hash distribution; but Symbols use the hash value based on the underlying string nowadays (r51410) > If we put the hypothesis of removing Symbols from ruby would that have > any negative impact on performance? Fundamentally they are different things, and I am not a semantics person. Performance should not change much if at all. The performance of most other languages is fine without symbols, including Perl5 which I consider a close relative of Ruby. > What other side effects could we envision? But again, I don't support breaking production code. We may need to support symbols in the language forever. Anyways, I enjoy typing symbols since they take less keystrokes and require less screen space, especially with 1.9+ JSON-like Hash syntax. However, symbols do take up more memory, since every symbol has an immutable fstring is attached to them along with symbol-specific data. Immutable strings only have extra overhead from being in the fstring table. Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>