Feature #26561

Frozen string literals

Added by Pavel Rosický about 1 month ago. Updated about 1 month ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Performance
Target version:4.1.0
Resolution:

Description

Hi, Ruby 2.3 introduced support for frozen string literals

Pros
  • less memory consumption
  • performance (less GC preasure)
  • safer code
Cons
  • mutable functions like force_encoding or gsub! can't be called on frozen strings anymore, this may cause incompatibility with some plugins, but it's very easy to fix and still maintain the backwards compatibility
  • a magic comment has to be added at the top of each rb file :-(

More information
https://www.pluralsight.com/blog/software-development/ruby-2-3--working-with-immutable-strings-

Many popular gems and libraries already did this - for example:
https://github.com/rails/rails/pull/29655
https://github.com/mikel/mail/pull/970

I attached a patch based on master that passes all tests.
There're some garbage changes like removed whitespaces, I'll clean it up if it's approved.

What do you think?

frozen_string_literals.patch Magnifier (541 KB) Pavel Rosický, 2017-07-27 22:12

History

#1 Updated by Toshi MARUYAMA about 1 month ago

  • Description updated (diff)

#2 Updated by Toshi MARUYAMA about 1 month ago

  • Target version set to 4.1.0

Also available in: Atom PDF