Skip to content

Precompute frozen string literals hash code #8408

Open
@headius

Description

@headius

Frozen string literals could have pre-computed hashcodes, saving some cost when using them in Hash or similar data structures.

Currently, we have a field for a cached hash in ByteList, but that field is not used for Ruby hash calculation. So we're already paying the cost to store a cached hash, but not actually using it. Experimentally using the ByteCode cached hash makes a benchmark of Hash access almost as fast for frozen literal strings as for Symbol:

              symbol   159.702M i/s -    150.472M times in 0.942205s (6.26ns/i)
          dyn_symbol   153.856M i/s -    150.140M times in 0.975848s (6.50ns/i)
           small_lit    68.630M i/s -    107.022M times in 1.559413s (14.57ns/i)
          frozen_lit   149.703M i/s -    156.283M times in 1.043955s (6.68ns/i)

CRuby has made this optimization only for embedded (all in header) literal strings here: ruby/ruby#10596

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy