Skip to content

Commit 0264424

Browse files
committed
Add test for GC thrashing of young object creation
This test will prevent performance regressions like [Bug #18929].
1 parent 8d40ede commit 0264424

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/ruby/test_gc.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,28 @@ def test_expand_heap
402402
eom
403403
end
404404

405+
def test_thrashing_for_young_objects
406+
# This test prevents bugs like [Bug #18929]
407+
408+
assert_separately %w[--disable-gem], __FILE__, __LINE__, <<-RUBY
409+
# Warmup to make sure heap stabilizes
410+
1_000_000.times { Object.new }
411+
412+
before_stats = GC.stat
413+
414+
1_000_000.times { Object.new }
415+
416+
after_stats = GC.stat
417+
418+
# Should not be thrashing in page creation
419+
assert_equal before_stats[:heap_allocated_pages], after_stats[:heap_allocated_pages]
420+
assert_equal 0, after_stats[:heap_tomb_pages]
421+
assert_equal 0, after_stats[:total_freed_pages]
422+
# Only young objects, so should not trigger major GC
423+
assert_equal before_stats[:major_gc_count], after_stats[:major_gc_count]
424+
RUBY
425+
end
426+
405427
def test_gc_internals
406428
assert_not_nil GC::INTERNAL_CONSTANTS[:HEAP_PAGE_OBJ_LIMIT]
407429
assert_not_nil GC::INTERNAL_CONSTANTS[:RVALUE_SIZE]

0 commit comments

Comments
 (0)