-
-
Notifications
You must be signed in to change notification settings - Fork 942
Description
Environment Information
jruby 9.3.2.0 (2.6.8) 2021-12-01 0b8223f OpenJDK 64-Bit Server VM 17.0.1+1 on 17.0.1+1 +jit [darwin-x86_64]
Expected Behavior
This is a simplified demonstration of an issue I ran into updating from jruby 9.2 to 9.3. Running our application's test suite under 9.3, we saw memory usage go from ~500MB to blowing the stack around 8GB. I was able to track it down to a couple culprits, but one of the biggest changes seems to come from calls to instance_eval, e.g.:
require 'java'
java_import 'java.lang.System'
import java.lang.management.ManagementFactory
mbean = ManagementFactory.getMemoryMXBean
Object.new.tap { |a| a.instance_eval('') }
System.gc
puts "A: #{mbean.getHeapMemoryUsage.used}"
50_000.times do |index|
Object.new.tap { |a| a.instance_eval('') }
end
System.gc
puts "B: #{mbean.getHeapMemoryUsage.used}"
Under jruby 9.2.20.1, the heap used before + after was kinda close (numeric formatting added):
A: 16,309,352
B: 20,393,896
The more text inside the instance_eval, the more memory seems to be retained somewhere.
Actual Behavior
Under jruby 9.3.2.0, a lot more information seems to be retained in the heap, even after GC:
A: 18,304,776
B: 69,164,056