Bug #22210
openCheck if issue #19969 is still reproducible / re-opened in 4.0.x
Description
Hi team,
I am writing to ask if Bug #19969 might still be reproducible in the current version of Ruby.
Could you please check if the issue is still present or if a regression has occurred?
I ran the reproduction script from #19969 across several Ruby versions on macOS (arm64-darwin), and while Ruby 3.2.4 fixed the high memory consumption (dropping to 29 MiB), Ruby 4.0.5 spikes back up to 2215 MiB.
ruby -v -rset -e 's1 = Set.new(10000.times); s2 = Set.new(9999.times); Array.new(10000) { s1 - s2 - [0] }; puts "#{`ps -o rss= -p #{$$}`.to_i / 1024} MiB"'
Results across versions:
Updated by jeremyevans0 (Jeremy Evans) 1 day ago
- Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: DONTNEED, 3.4: DONTNEED, 4.0: REQUIRED
Thank you for the report. I looked into this and the related functions for st_table are implemented for set_table (set_rebuild_table_with, set_rebuild_move_table, set_rebuild_cleanup, rb_set_compact_table). For the Set class, set_compact_after_delete is implemented, and the following functions call it:
deletedelete?delete_ifreject!clear
Methods that remove elements from a set but did not call set_compact_after_delete:
^-differencesubtractkeep_ifselect!filter!
I've submitted a pull request to fix these issues: https://github.com/ruby/ruby/pull/18058