[ruby-cvs:54904] normal:r47756 (trunk): marshal.c: lazy compat_tbl allocation

normal at ruby-lang.org normal at ruby-lang.org
Thu Oct 2 05:29:48 JST 2014


normal	2014-10-02 05:29:46 +0900 (Thu, 02 Oct 2014)

  New Revision: 47756

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

  Log:
    marshal.c: lazy compat_tbl allocation
    
    In some common cases, compat_tbl is unused in dump_arg/load_arg,
    so avoid malloc/free costs for the unused table.
    
    ruby -e 'h = {a: :b}; 600000.times { Marshal.load(Marshal.dump(h)) }'
    
    before:
    real    0m2.458s
    user    0m2.450s
    sys     0m0.006s
    
    after:
    real    0m2.122s
    user    0m2.110s
    sys     0m0.011s
    
    * marshal.c (w_class): check dump_arg->compat_tbl before lookup
      (w_object): lazy init ->compat_tbl before insert
      (obj_alloc_by_class): ditto
      (clear_dump_arg): free only non-NULL ->compat_tbl
      (clear_load_arg): ditto for ->compat_tbl
      (marshal_dump): ->compat_tbl defaults to zero
      (marshal_load): ditto for ->compat_tbl
      (r_entry0): check l->compat_tbl before lookup
      (r_fixup_compat): ditto

  Modified files:
    trunk/ChangeLog
    trunk/marshal.c


More information about the ruby-cvs mailing list