From 9b405a18bea7825cba794e42a1fef58a48451ec3 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 21 Feb 2023 12:38:25 +0100 Subject: 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. --- test/ruby/test_process.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 6ca16733bb..9846f5e2db 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -2709,4 +2709,16 @@ EOS assert_equal compact_count + 1, GC.stat(:compact_count) end; end + + def test_warmup_precompute_string_coderange + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + require 'objspace' + begin; + obj = "a" * 12 + obj.force_encoding(Encoding::BINARY) + assert_include(ObjectSpace.dump(obj), '"coderange":"unknown"') + Process.warmup + assert_include(ObjectSpace.dump(obj), '"coderange":"7bit"') + end; + end end -- cgit v1.2.3