[ruby-cvs:65664] shyouhei:r58492 (trunk): refactor newhash (revision 58463 another try) [fix GH-1600]

shyouhei at ruby-lang.org shyouhei at ruby-lang.org
Thu Apr 27 13:21:04 JST 2017


shyouhei	2017-04-27 13:21:04 +0900 (Thu, 27 Apr 2017)

  New Revision: 58492

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58492

  Log:
    refactor newhash (revision 58463 another try) [fix GH-1600]
    
    * st.c (rb_hash_bulk_insert): new API to bulk insert entries
      into a hash. Given arguments are first inserted into the
      table at once, then reindexed. This is faster than inserting
      things using rb_hash_aset() one by one.
    
      This arrangement (rb_ prefixed function placed in st.c) is
      unavoidable because it both touches table internal and write
      barrier at once.
    
    * internal.h: delcare the new function.
    
    * hash.c (rb_hash_s_create): use the new function.
    
    * vm.c (core_hash_merge): ditto.
    
    * insns.def (newhash): ditto.
    
    * test/ruby/test_hash.rb: more coverage on hash creation.
    
    * test/ruby/test_literal.rb: ditto.
    
    -----------------------------------------------------------
    benchmark results:
    minimum results in each 7 measurements.
    Execution time (sec)
    name    before  after
    loop_whileloop2  0.136  0.137
    vm2_bighash*     1.249  0.623
    
    Speedup ratio: compare with the result of `before' (greater is better)
    name    after
    loop_whileloop2 0.996
    vm2_bighash*    2.004

  Modified files:
    trunk/hash.c
    trunk/insns.def
    trunk/internal.h
    trunk/st.c
    trunk/test/ruby/test_hash.rb
    trunk/test/ruby/test_literal.rb
    trunk/vm.c


More information about the ruby-cvs mailing list