[#70257] [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI — ko1@...

Issue #11420 has been reported by Koichi Sasada.

11 messages 2015/08/06

[ruby-core:70593] [Ruby trunk - Feature #8976] file-scope freeze_string directive

From: mame@...
Date: 2015-08-25 16:30:15 UTC
List: ruby-core #70593
Issue #8976 has been updated by Yusuke Endoh.


Yusuke Endoh wrote:
> I'm interested in the actual effect of this feature.  How many times faster will Rails run actually?  Anyone measured?

I did.

Experimental overview:

* I used [akr's "immutable by default" branch](https://github.com/akr/ruby/tree/frozen-string)
* I executed:
  * `gem install rails`
  * `rails new scaffold-test`
  * `rails s`
  * open "Welcome aboard" page
  * `ab -u 1000 -c 100 http://localhost:3000`
* I compared it with 2.2.1p85 (released version)
* Whenever "`can't modify frozen String`" exception is raised, I created and applied a very ad-hoc fix.  I didn't count the fixes precisely, but I think about 50 fixes are needed.  (rdoc, bundler, and gem install sqlite3, required many fixes.)

Results: Requests per second

* immutable by default branch:  167.14 [#/sec] 
* 2.2.1p85: 168.42 [#/sec] 

I tried a few times, but I couldn't see any difference.

Note:

* The current source of Rails already includes many `.freeze` literals.  So there may be little room for improvement by this feature.  The same experiment with removing all `.freeze` might be valuable.
* I don't know how meaningful it is to measure the "requests per second" of "Welcome aboard" page on WEBrick.
* My fixes for "`can't modify frozen String`" is really ad-hoc; they may break something.
* Sorry, I didn't record my fixes, so I cannot provide the sufficient information for replication.  But I could perform this experiment in a few hours, so I think it is not so difficult for other people to replicate this experiment.  (I'm not familiar with Rails.  Actually I used Rails for the first time in about 8 years.)

-- 
Yusuke Endoh <mame@ruby-lang.org>

----------------------------------------
Feature #8976: file-scope freeze_string directive
https://bugs.ruby-lang.org/issues/8976#change-53998

* Author: Akira Tanaka
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Yesterday, we had a face-to-face developer meeting.
https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20131001Japan
Several committers attended.
matz didn't attended, though.  (This means this issue is not concluded.)

We believe we found a better way to freeze static string literals for
less GC pressure.
"static string literal" is a string literal without dynamic expression.

Currently, f-suffix, "..."f, is used to freeze a string literal to avoid
String object allocation.

There are several problems for f-suffix:

* The notation is ugly.
* Syntax error on Ruby 2.0.
  We cannot use the feature in version independent libraries.
  So, it is difficult to deploy.
* Need to modify for each string literal.
  This is cumbersome.

The new way we found is a file-scope directive as follows

  # freeze_string: true

The above comment at top of a file changes semantics of
static string literals in the file.
The static string literals will be frozen and always returns same object.
(The semantics of dynamic string literals is not changed.)

This way has following benefits:

* No ugly f-suffix.
* No syntax error on older Ruby.
* We need only a line for each file.

We can write version independent library using frozen static string literals as follows.

* Use the directive at top of the file: # freeze_string: true
  Older Ruby ignore this as a comment.
* Use "...".dup for strings to be modified.
  Older Ruby has small disadvantage: useless dup is called.

Note that the directive effects all static string literals regardless of
single quotes, double quotes, %q-string, %qq-string and here documents.
The reason that the directive is effective not only single quotes is
we want to use escape sequences such as \n in frozen string literals.

Also note that similar directive is already exist:

  % ruby -w -e '
  def m
    end
  '
  -e:3: warning: mismatched indentations at 'end' with 'def' at 2
  % ruby -w -e '# -*- warn_indent: false -*-
  def m
    end
  '

The directive, warn_indent: false, disables "mismatched indentations" warning.

nobu implemented this feature in the meeting.
Please attach the patch, nobu.




-- 
https://bugs.ruby-lang.org/

In This Thread