[#61171] Re: [ruby-changes:33145] normal:r45224 (trunk): gc.c: fix build for testing w/o RGenGC — SASADA Koichi <ko1@...>
(2014/03/01 16:15), normal wrote:
[#61243] [ruby-trunk - Feature #9425] [PATCH] st: use power-of-two sizes to avoid slow modulo ops — normalperson@...
Issue #9425 has been updated by Eric Wong.
[#61359] [ruby-trunk - Bug #9609] [Open] [PATCH] vm_eval.c: fix misplaced RB_GC_GUARDs — normalperson@...
Issue #9609 has been reported by Eric Wong.
(2014/03/07 19:09), normalperson@yhbt.net wrote:
SASADA Koichi <ko1@atdot.net> wrote:
[#61424] [REJECT?] xmalloc/xfree: reduce atomic ops w/ thread-locals — Eric Wong <normalperson@...>
I'm unsure about this. I _hate_ the extra branches this adds;
Hi Eric,
SASADA Koichi <ko1@atdot.net> wrote:
(2014/03/14 2:12), Eric Wong wrote:
SASADA Koichi <ko1@atdot.net> wrote:
[#61452] [ruby-trunk - Feature #9632] [Open] [PATCH 0/2] speedup IO#close with linked-list from ccan — normalperson@...
Issue #9632 has been reported by Eric Wong.
[#61496] [ruby-trunk - Feature #9638] [Open] [PATCH] limit IDs to 32-bits on 64-bit systems — normalperson@...
Issue #9638 has been reported by Eric Wong.
[#61568] hash function for global method cache — Eric Wong <normalperson@...>
I came upon this because I noticed existing st numtable worked poorly
(2014/03/18 8:03), Eric Wong wrote:
SASADA Koichi <ko1@atdot.net> wrote:
what's the profit from using binary tree in place of hash?
Юрий Соколов <funny.falcon@gmail.com> wrote:
[#61687] [ruby-trunk - Bug #9606] Ocassional SIGSEGV inTestException#test_machine_stackoverflow on OpenBSD — normalperson@...
Issue #9606 has been updated by Eric Wong.
[#61760] [ruby-trunk - Feature #9632] [PATCH 0/2] speedup IO#close with linked-list from ccan — normalperson@...
Issue #9632 has been updated by Eric Wong.
[ruby-core:61486] [ruby-trunk - Feature #9634] [PATCH]Symbol GC
Issue #9634 has been updated by Narihiro Nakamura.
Description updated
----------------------------------------
Feature #9634: [PATCH]Symbol GC
https://bugs.ruby-lang.org/issues/9634#change-45779
* Author: Narihiro Nakamura
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category: core
* Target version: current: 2.2.0
----------------------------------------
I've written a patch to collect most symbols.
PATCH: https://github.com/authorNari/ruby/compare/4a91fb7a45f0e3c...symbol_gc.patch
## Summary
* Most symbols in Ruby level are GC-able(generated by #to_sym, #intern, etc..)
* Exclude a symbol which is translated ID in C-level from GC-able symbols
* Keep Ruby's C extension compatibility
* Pass `make test-all`
## Benchmark
A benchmark program is here.
```
obj = Object.new
100_000.times do |i|
obj.respond_to?("sym#{i}".to_sym)
end
GC.start
puts"symbol : #{Symbol.all_symbols.size}"
```
```
% time RBENV_VERSION=ruby-r45059 ruby -v /tmp/a.rb
ruby 2.2.0dev (2014-02-20 trunk 45059) [x86_64-linux]
symbol : 102416
0.24s user 0.01s system 91% cpu 0.272 total
% time RBENV_VERSION=symgc ruby -v /tmp/a.rb
ruby 2.2.0dev (2014-02-20 trunk 45059) [x86_64-linux]
symbol : 2833
0.21s user 0.01s system 90% cpu 0.247 total
```
The total number of symbols is declined.
The total time of symgc version is improved because Full GC pressure has been reduced.
The result of `make benchmark`.
https://gist.github.com/authorNari/9359704
There is no significant slowdown.
(I would welcome to try an additional benchmark and report)
## Implementation Detail
I classify Dynamic symbol and Static symbol.
* Static symbol
* Generated by rb_itnern()
* A sequential unique number as in the past.
* Not GC-able
* LSB = 1
* Reserved IDs(147 and below) are exceptional cases
* Dynamic symbol
* Generated by #to_sym, #intern in Ruby level
* RVALUE
* GC-able
* LSB = 0
* Pin down a dynamic symbol when it translate to ID (e.g. SYM2ID, rb_intern).
* Pinned dynamic symbols are never collected.
* I'd like to include ID in GC's roots only CRuby internal in order to reduce pinned dynamic symbols.
Please read the patch if you want to know more information.
## Acknowledgment
The idea of this symbol GC is invented by Sasada Koichi in Heroku,inc.
Thank you.
-- ja --
RubyレベルのシンボルをGC対象にするパッチを書きました。
https://github.com/authorNari/ruby/compare/4a91fb7a45f0e3c...symbol_gc
## 概要
* RubyレベルのほとんどのシンボルがGC対象(to_sym,internで作られたもの)
* C側でIDに変換された場合はGC対象から除外(rb_intern、SYM2IDなど)
* C-APIの互換性維持
* make test-allが通る
## ベンチマーク
以下のプログラムを実行。
```
obj = Object.new
100_000.times do |i|
obj.respond_to?("sym#{i}".to_sym)
end
GC.start
puts"symbol : #{Symbol.all_symbols.size}"
```
```
% time RBENV_VERSION=symgc ruby -v /tmp/a.rb
ruby 2.2.0dev (2014-02-20 trunk 45059) [x86_64-linux]
symbol : 2833
0.21s user 0.01s system 90% cpu 0.247 total
% time RBENV_VERSION=ruby-r45059 ruby -v /tmp/a.rb
ruby 2.2.0dev (2014-02-20 trunk 45059) [x86_64-linux]
symbol : 102416
0.24s user 0.01s system 91% cpu 0.272 total
```
総シンボル数が減少していることがわかる。
シンボル数の現象でFull GCのプレッシャーが削減されたことにより、symgcの速度が向上した。
make benchmarkの結果。
https://gist.github.com/authorNari/9359704
大幅な速度低下は見られない。
(上記以外の追試を歓迎します)
## (ちょっとした)詳細
symbolをstatic symbolとdynamic symbolに分類。
* static symbol
* rb_itnernなどで生成されたもの
* 従来通り、連番の一意な数値
* GC非対象
* 下位1ビットにフラグとして1を立てる
* 147以下の予約済みIDは例外ケース
* dynamic symbol
* Rubyレベルの#to_sym,#internなどで生成されたもの
* RVALUEとして生成
* GC対象
* 下位1ビットは0
* CレベルでID変換(SYM2IDなど)された場合、pindownし、GCで解放されなくなる
* Ruby内部でIDはルートに含め、pindownする箇所をなくしたい
その他の詳細はパッチを読んでもらえると…。
## 謝辞
シンボルGCのアイデアはHeroku社のささだこういち様によるものです。
ありがとうございます。
-----
---Files--------------------------------
test-all_segfault.log (10 KB)
--
http://bugs.ruby-lang.org/