diff options
author | Peter Zhu <[email protected]> | 2021-11-19 14:51:58 -0500 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2021-11-23 10:51:27 -0500 |
commit | 9aded89f4071a8afb79326701789241f1da12f82 (patch) | |
tree | 4869f264a95718d7c6882564cf0d19a913fe952e /string.c | |
parent | c14f230b26aa4f8abe9ecf3814cfebbe584d77c9 (diff) |
Speed up Ractors for Variable Width Allocation
This commit adds a Ractor cache for every size pool. Previously, all VWA
allocated objects used the slowpath and locked the VM.
On a micro-benchmark that benchmarks String allocation:
VWA turned off:
29.196591 0.889709 30.086300 ( 9.434059)
VWA before this commit:
29.279486 41.477869 70.757355 ( 12.527379)
VWA after this commit:
16.782903 0.557117 17.340020 ( 4.255603)
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5151
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -868,7 +868,9 @@ static inline VALUE empty_str_alloc(VALUE klass) { RUBY_DTRACE_CREATE_HOOK(STRING, 0); - return str_alloc_embed(klass, 0); + VALUE str = str_alloc_embed(klass, 0); + memset(RSTRING(str)->as.embed.ary, 0, str_embed_capa(str)); + return str; } static VALUE @@ -1732,10 +1734,11 @@ str_duplicate_setup(VALUE klass, VALUE str, VALUE dup) VALUE flags = FL_TEST_RAW(str, flag_mask); int encidx = 0; if (STR_EMBED_P(str)) { - assert(str_embed_capa(dup) >= RSTRING_EMBED_LEN(str)); - STR_SET_EMBED_LEN(dup, RSTRING_EMBED_LEN(str)); - MEMCPY(RSTRING(dup)->as.embed.ary, RSTRING(str)->as.embed.ary, - char, RSTRING_EMBED_LEN(str)); + long len = RSTRING_EMBED_LEN(str); + + assert(str_embed_capa(dup) >= len + 1); + STR_SET_EMBED_LEN(dup, len); + MEMCPY(RSTRING(dup)->as.embed.ary, RSTRING(str)->as.embed.ary, char, len + 1); flags &= ~RSTRING_NOEMBED; } else { @@ -2321,6 +2324,7 @@ rb_str_times(VALUE str, VALUE times) if (RSTRING_LEN(str) == 1 && RSTRING_PTR(str)[0] == 0) { if (STR_EMBEDDABLE_P(len, 1)) { str2 = str_alloc_embed(rb_cString, len + 1); + memset(RSTRING_PTR(str2), 0, len + 1); } else { str2 = str_alloc_heap(rb_cString); |