small medium large xlarge

Generic-user-small
29 Dec 2015, 11:34
Radoslaw Bulat (4 posts)
$ RBENV_VERSION=2.2 ruby each_bang.rb | tail -2
1000
0
$ RBENV_VERSION=2.3 ruby each_bang.rb | tail -2
1000
1000

Maybe it is a bug in ruby 2.3 GC?

Generic-user-small
24 Mar 2016, 02:53
Brian Davis (6 posts)

I just noticed this. Is there an explanation for this?

0ba3be7_pragsmall
24 Mar 2016, 02:59
Alexander Dymo (9 posts)

It doesn’t happen for me even with 2.3. Could you please try replacing GC.start calls with:

GC.start(full_mark: true, immediate_sweep: true, immediate_mark: false)
Generic-user-small
24 Mar 2016, 05:27
Brian Davis (6 posts)

I’ve isolated the issue:

If I change

list = nil

to

list.clear

I get the right results.

ch2 $ rvm use 2.2.3 && ruby each_bang.rb tail -4

Using /Users/briandavis/.rvm/gems/ruby-2.2.3

1000

after iterator

0

after clear

ch2 $ rvm use 2.3.0 && ruby each_bang.rb tail -4

Using /Users/briandavis/.rvm/gems/ruby-2.3.0

1000

after iterator

0

after clear

Otherwise, I get the same results as above

Generic-user-small
24 Mar 2016, 05:25
Brian Davis (6 posts)

Using GC.start(full_mark: true, immediate_sweep: true, immediate_mark: false) doesn’t change anything for me.

Generic-user-small
15 Mar 2017, 21:10
Edmund (1 post)

I used docker to containerize the environment and benchmark each! compare with each. There is no difference. They blew up the memory after roughly the same number of iterations.

Here’s the simple snippet I used. Any idea why?

puts 'Array#each'
puts 'creating array'
arr = Array.new(10000) { '-' * 100 }
arr_1 = []
puts 'finished creating array'
puts 'each iteration begins'

i = 0
arr.each do |el|
  new_el = '+' * 100
  arr_1 << new_el
  end
end
You must be logged in to comment