From 762bf7f8f474ab1efa40f47dfe498847ce04ac02 Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Thu, 25 Jun 2026 09:57:53 +0100 Subject: [PATCH] Add string malloc pressure benchmark This benchmark allocates a large amount of malloc backed strings and keeps them alive in the heap. It is intended to exercise GC's triggered by malloc pressure. --- benchmarks.yml | 5 +++++ benchmarks/string_malloc_pressure.rb | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 benchmarks/string_malloc_pressure.rb diff --git a/benchmarks.yml b/benchmarks.yml index 0035bf87..b0ef6651 100644 --- a/benchmarks.yml +++ b/benchmarks.yml @@ -136,6 +136,11 @@ sudoku: splay: desc: Splay tree operations (insert, find, remove) to stress GC. single_file: true +string_malloc_pressure: + desc: Allocates and retains many empty Strings with large reserved capacity to exercise GC under malloc-backed String buffer pressure. + category: gc + single_file: true + default_harness: harness-gc tinygql: desc: TinyGQL gem parsing a large file in pure Ruby diff --git a/benchmarks/string_malloc_pressure.rb b/benchmarks/string_malloc_pressure.rb new file mode 100644 index 00000000..ebda6860 --- /dev/null +++ b/benchmarks/string_malloc_pressure.rb @@ -0,0 +1,12 @@ +require_relative '../harness/loader' + +def build_string_malloc_pressure + live = [] + 500.times do + live << Array.new(200) { String.new(capacity: 64 * 1024) } + end +end + +run_benchmark(10) do + build_string_malloc_pressure +end