diff options
author | Jean Boussier <[email protected]> | 2024-04-08 12:04:01 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2024-05-28 07:32:41 +0200 |
commit | 9e9f1d9301b05604d475573ddd18d6bf5185466c (patch) | |
tree | f21078b5fee9ad5afc2f25d3f1b625f5468e3687 /internal/string.h | |
parent | 1376881e9afe6ff673f64afa791cf30f57147ee2 (diff) |
Precompute embedded string literals hash code
With embedded strings we often have some space left in the slot, which
we can use to store the string Hash code.
It's probably only worth it for string literals, as they are the ones
likely to be used as hash keys.
We chose to store the Hash code right after the string terminator as to
make it easy/fast to compute, and not require one more union in RString.
```
compare-ruby: ruby 3.4.0dev (2024-04-22T06:32:21Z main f77618c1fa) [arm64-darwin23]
built-ruby: ruby 3.4.0dev (2024-04-22T10:13:03Z interned-string-ha.. 8a1a32331b) [arm64-darwin23]
last_commit=Precompute embedded string literals hash code
| |compare-ruby|built-ruby|
|:-----------|-----------:|---------:|
|symbol | 39.275M| 39.753M|
| | -| 1.01x|
|dyn_symbol | 37.348M| 37.704M|
| | -| 1.01x|
|small_lit | 29.514M| 33.948M|
| | -| 1.15x|
|frozen_lit | 27.180M| 33.056M|
| | -| 1.22x|
|iseq_lit | 27.391M| 32.242M|
| | -| 1.18x|
```
Co-Authored-By: Étienne Barrié <[email protected]>
Diffstat (limited to 'internal/string.h')
-rw-r--r-- | internal/string.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/internal/string.h b/internal/string.h index 3333b3afc3..3533766ffb 100644 --- a/internal/string.h +++ b/internal/string.h @@ -80,6 +80,7 @@ VALUE rb_str_concat_literals(size_t num, const VALUE *strary); VALUE rb_str_eql(VALUE str1, VALUE str2); VALUE rb_id_quote_unprintable(ID); VALUE rb_sym_proc_call(ID mid, int argc, const VALUE *argv, int kw_splat, VALUE passed_proc); +VALUE rb_enc_literal_str(const char *ptr, long len, rb_encoding *enc); struct rb_execution_context_struct; VALUE rb_ec_str_resurrect(struct rb_execution_context_struct *ec, VALUE str, bool chilled); |