[ruby-cvs:66482] normal:r59304 (trunk): Hash#[]= deduplicates string keys if (and only if) fstring exists

normal at ruby-lang.org normal at ruby-lang.org
Mon Jul 10 08:04:43 JST 2017


normal	2017-07-10 08:04:43 +0900 (Mon, 10 Jul 2017)

  New Revision: 59304

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

  Log:
    Hash#[]= deduplicates string keys if (and only if) fstring exists
    
    In typical applications, hash entries are read after being
    written to.  Blindly writing to hashes which are never read
    makes little sense. So, for any hash which is read from, an
    fstring entry for the key should already exist for the key.
    
    We no longer blindly create fstrings if the code is blindly
    setting random hash keys, preventing the performance regression
    in the reverted r43870.
    
    Regarding <https://bugs.ruby-lang.org/issues/9188>, this has a
    minimum impact on the bm_so_k_nucleotide where hash keys are set
    and not reused, performance is within 1-2% of existing cases.
    
    * hash.c: #include gc.h for rb_objspace_garbage_object_p
      (hash_aset_str): do read-only check of fstring table and
      reuse fstring if it exists and is still alive (not garbage)
      [ruby-core:81942] [Feature #13725]

  Modified files:
    trunk/hash.c


More information about the ruby-cvs mailing list