Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kasatani opened this issue Jul 3, 2016 · 2 comments
Closed
Milestone

Comments

@kasatani
Copy link

kasatani commented Jul 3, 2016

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
@headius
Copy link
Member

headius commented Jul 11, 2016

Nice crash! Double-feature with a full code cache AND a stack overflow.

I suspect this is the same problem as #4003 which was fixed in d15e35a. Give a nightly 9.1.3.0 snapshot a try and reopen if you still see the issue.

@headius headius closed this as completed Jul 11, 2016
@headius headius added this to the JRuby 9.1.3.0 milestone Jul 11, 2016
@kasatani
Copy link
Author

Thank you. I've tested it with the nightly snapshot and it doesn't crash any more.

However it's still slower than JRuby 1.7.19. It takes less than 1 second in JRuby 1.7 and about 6 seconds in JRuby 9.1.3.0-SNAPSHOT. Not a big problem though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants