summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorJean Boussier <byroot@ruby-lang.org>2023-02-21 12:38:25 +0100
committerJean Boussier <jean.boussier@gmail.com>2023-07-26 11:41:23 +0200
commit9b405a18bea7825cba794e42a1fef58a48451ec3 (patch)
treeebe4d86d88df1a9dad5ea0e19e39d1b47ce6ca2f /gc.c
parent283b2fdab4be77d8721d7cf298168eb6e3798490 (diff)
Process.warmup: precompute strings coderange
This both save time for when it will be eventually needed, and avoid mutating heap pages after a potential fork. Instrumenting some large Rails app, I've witnessed up to 58% of String instances having their coderange still unknown.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/8112
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/gc.c b/gc.c
index 3c9adf3b00..ca018b7ae1 100644
--- a/gc.c
+++ b/gc.c
@@ -9596,6 +9596,11 @@ gc_set_candidate_object_i(void *vstart, void *vend, size_t stride, void *data)
case T_NONE:
case T_ZOMBIE:
break;
+ case T_STRING:
+ // precompute the string coderange. This both save time for when it will be
+ // eventually needed, and avoid mutating heap pages after a potential fork.
+ rb_enc_str_coderange(v);
+ // fall through
default:
if (!RVALUE_OLD_P(v) && !RVALUE_WB_UNPROTECTED(v)) {
RVALUE_AGE_SET_CANDIDATE(objspace, v);