Skip to content

Performance issue when extending objects with a module including constants  #3993

@kasatani

Description

@kasatani

The following code runs extremely slow on JRuby 9.1.2.0. It defines a module with a constant and a method that refers to the constant, and then create objects that are extended by the module and call the method defined in the module.

I couldn't find the reason but it gets slower over time and eventually crashes with java.lang.StackOverflowError.

module M
  X = 1
  def x(v)
    v == X
  end
end

time = Time.now
100000.times do |i|
  o = ''
  o.extend(M)
  o.x(i)
  p (Time.now - time).to_i if i % 1000 == 0
end

It runs smoothly when there are no constants defined in the module.

Environment

  • JRuby 9.1.2.0
  • java version "1.8.0_20"
  • OS X 10.11.5 (same problem on Linux as well)

Expected Behavior

  • The script runs within 1 second. (It prints 100 "0"s on MRI 2.2.2 and JRuby 1.7.19.)

Actual Behavior

0
2
7
14
25
38
54
74
94
115
139
167
193
Java HotSpot(TM) 64-Bit Server VM warning: CodeCache is full. Compiler has been disabled.
Java HotSpot(TM) 64-Bit Server VM warning: Try increasing the code cache size using -XX:ReservedCodeCacheSize=
CodeCache: size=245760Kb used=213510Kb max_used=213736Kb free=32249Kb
 bounds [0x000000010611b000, 0x000000011511b000, 0x000000011511b000]
 total_blobs=15266 nmethods=14704 adapters=473
 compilation: disabled (not enough contiguous free space left)
219
245
274
Error: Your application used more stack memory than the safety cap of 2048K.
Specify -J-Xss####k to increase it (#### = cap size in KB).
Specify -w for full java.lang.StackOverflowError stack trace

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions