Skip to content

Commit

Permalink
Try reducing n^2 complexity here
Browse files Browse the repository at this point in the history
This should not time out, but if GC takes a while to process weak
references the original code will scan over 50M weakrefs and run
full GC 10k times before giving up. This change reduces the total
number of weakrefs to 1000 and only scans them with GC.start up
to 1000 times. If that is not enough GC to trigger weakref
evacuation then it should just fail.
  • Loading branch information
headius committed Mar 2, 2021
1 parent a7f1480 commit c4ae884
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions spec/ruby/library/weakref/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ def self.make_weakref(level = 10)
def self.make_dead_weakref
weaks = []
weak = nil
10_000.times do
1000.times do
weaks << make_weakref
GC.start
end

1000.times do
GC.start
break if weak = weaks.find { |w| !w.weakref_alive? }
end
Expand Down

0 comments on commit c4ae884

Please sign in to comment.