Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RubyKaigi 2024 にみんなで参加した Techouse の その後の進捗 wit...

Techouse
September 05, 2024

RubyKaigi 2024 にみんなで参加した Techouse の その後の進捗 with Ruby

Techouse

September 05, 2024
Tweet

More Decks by Techouse

Other Decks in Programming

Transcript

  1. RubyKaigi 2024 にみんなで参加した Techouse の その後の進捗 with Ruby RubyKaigi 2024

    follow up スポンサーLT 2024.8.31 Techouse 山崎良祐 ( @nappa )
  2. struct RObject { /** Basic part, including flags and class.

    */ struct RBasic basic; /** Object's specific fields. */ union { struct { VALUE *ivptr; struct rb_id_table *iv_index_tbl; } heap; /* Embedded instance variables. When an object is small enough, it * uses this area to store the instance variables. */ VALUE ary[1]; } as; }; Ruby Object (RObject型) https://github.com/ruby/ruby/blob/master/include/ruby/internal/core/robject. h Cソース (robject.h) RBasic VALUE *ivptr struct rb_id_table *iv_index_tbl; RObject 社内イベント資料より抜粋
  3. struct RObject { /** Basic part, including flags and class.

    */ struct RBasic basic; /** Object's specific fields. */ union { struct { VALUE *ivptr; struct rb_id_table *iv_index_tbl; } heap; /* Embedded instance variables. When an object is small enough, it * uses this area to store the instance variables. */ VALUE ary[1]; } as; }; Ruby Object (RObject型) https://github.com/ruby/ruby/blob/master/include/ruby/internal/core/robject. h Cソース (robject.h) Struct RBasic VALUE *ivptr struct rb_id_table *iv_index_tbl; RObject 社内イベント資料より抜粋
  4. struct RBasic { /** * Per-object flags. Each Ruby object

    has its own characteristics apart * from its class. For instance, whether an object is frozen or not is not * controlled by its class. This is where such properties are stored. * * @see enum ::ruby_fl_type * * @note This is ::VALUE rather than an enum for alignment purposes. Back * in the 1990s there were no such thing like `_Alignas` in C. */ VALUE flags; /** * Class of an object. Every object has its class. Also, everything is an * object in Ruby. This means classes are also objects. Classes have * their own classes, classes of classes have their classes too, and it * recursively continues forever. * * Also note the `const` qualifier. In Ruby, an object cannot "change" its * class. */ const VALUE klass; }; Ruby Object 共通データ (RBasic 型) https://github.com/ruby/ruby/blob/master/include/ruby/internal/core/robject. Cソース (rbasic.h) VALUE *ivptr struct rb_id_table *iv_index_tbl; RObject struct RBasic VALUE flags VALUE klass 社内イベント資料より抜粋
  5. struct RBasic { /** * Per-object flags. Each Ruby object

    has its own characteristics apart * from its class. For instance, whether an object is frozen or not is not * controlled by its class. This is where such properties are stored. * * @see enum ::ruby_fl_type * * @note This is ::VALUE rather than an enum for alignment purposes. Back * in the 1990s there were no such thing like `_Alignas` in C. */ VALUE flags; /** * Class of an object. Every object has its class. Also, everything is an * object in Ruby. This means classes are also objects. Classes have * their own classes, classes of classes have their classes too, and it * recursively continues forever. * * Also note the `const` qualifier. In Ruby, an object cannot "change" its * class. */ const VALUE klass; }; Ruby Object 共通データ (RBasic 型) https://github.com/ruby/ruby/blob/master/include/ruby/internal/core/robject. Cソース (rbasic.h) VALUE *ivptr struct rb_id_table *iv_index_tbl; RObject struct RBasic VALUE flags VALUE klass 社内イベント資料より抜粋
  6. Ruby Object 共通データ (RBasic 型) VALUE *ivptr struct rb_id_table *iv_index_tbl;

    RObject struct RBasic VALUE flags VALUE klass インスタンス変数を収納する配列へのポインタ メソッドを探索するハッシュテーブルへのポインタ クラス フラグ (freeze or not, GC のマーク (後述)) 社内イベント資料より抜粋
  7. P28 ©︎Techouse All Rights Reserved 4.8 sec 5.1 sec 0から1億までの数を

    ソート済にした配列のなかの 奇数をかぞえる 0から1億までの数を シャッフルした配列のなかの 奇数をかぞえる 分岐予測に当たるとき・当たらないときに計算コストの差
  8. P29 ©︎Techouse All Rights Reserved 2次元配列を 行→列方向に アクセス 2次元配列を 列→行方向に

    アクセス 6.4 sec 12.9 sec キャッシュメモリに当たるとき・当たらないときの計算コストの差
  9. P30 ©︎Techouse All Rights Reserved 3.4 sec 6.0 sec 2**63

    に 10000000回 ゼロを足す 0に 10000000回 ゼロを足す 固定長整数と可変長整数の計算コストの差