[Documentation/Wiki] FAQ entry about frozen strings? #6626
-
Hey there headius and others, I have used ruby for many years; slowly learning ruby and getting Anyway - there is a super-simple question I have. Does: "# frozen_string_literal: true" In a given .rb file, have any effect via jruby? Right now I am invoke it on linux in this way:
And that works, the swing-JButton works fine, all cool. I don't Would it be possible to add an entry to the FAQ about it? QUESTION: Does using "# frozen_string_literal: true" in a .rb file have any performance-specific effect? Reason why this would be nice to the FAQ would be so that it is not forgotten; github issues tend to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The frozen string directive will have the same effect on performance as it would in standard Ruby: less allocation of String objects. Ruby Strings passed to Java calls are always converted into Java Strings, which are themselves immutable, so this doesn't really change anything about calling into Java. It may offer a possible performance improvement in the future if we cache the Java String object that corresponds to a given frozen literal String (but we are reluctant to fill memory with more String data than necessary). |
Beta Was this translation helpful? Give feedback.
The frozen string directive will have the same effect on performance as it would in standard Ruby: less allocation of String objects.
Ruby Strings passed to Java calls are always converted into Java Strings, which are themselves immutable, so this doesn't really change anything about calling into Java. It may offer a possible performance improvement in the future if we cache the Java String object that corresponds to a given frozen literal String (but we are reluctant to fill memory with more String data than necessary).